Javascript 部署Google Chrome扩展;Adobe Flash Player已停止可能不安全的操作
我想知道如何最好地处理Google Chrome扩展中没有足够权限的问题。我正在与YouTube API交互,但我没有使用swfobject.js,只是使用am embdeded div。我不认为这会引入我的安全问题,但也许是这样 在开发过程中,我必须导航到Adobe的flash player安全页面,并将我的开发文件夹指定为“安全”位置。在部署中,我没有能力做到这一点。我不希望我的用户必须点击flash player安全上的“允许所有”,但我看不到实现我的结果的其他方法 有人有处理这件事的经验吗?我有什么选择 似乎是重复的,但仍然没有答案 资料来源: 要运行:从repo中拉出,加载Chrome,单击扳手,转到extension,选中“Developer Tools”->加载未打包的extension并浏览到该文件夹Javascript 部署Google Chrome扩展;Adobe Flash Player已停止可能不安全的操作,javascript,flash,google-chrome,google-chrome-extension,youtube-api,Javascript,Flash,Google Chrome,Google Chrome Extension,Youtube Api,我想知道如何最好地处理Google Chrome扩展中没有足够权限的问题。我正在与YouTube API交互,但我没有使用swfobject.js,只是使用am embdeded div。我不认为这会引入我的安全问题,但也许是这样 在开发过程中,我必须导航到Adobe的flash player安全页面,并将我的开发文件夹指定为“安全”位置。在部署中,我没有能力做到这一点。我不希望我的用户必须点击flash player安全上的“允许所有”,但我看不到实现我的结果的其他方法 有人有处理这件事的经验
在操作中:由于原点限制,您不能使用
元素。相反,嵌入
,并使用YouTube播放器API与帧通信
将您的函数onyotubeplayerready
和函数初始化(播放列表)
替换为以下内容(在中):
要使前面的代码正常工作,必须在中加载另一个脚本。的内容基于我之前对的回答:
// @description Easier way to implement the YouTube JavaScript API
// @author Rob W
// @global getFrameID(id) Quick way to find the iframe object which corresponds to the given ID.
// @global YT_ready(Function:function [, Boolean:qeue_at_start])
// @global onYouTubePlayerAPIReady() - Used to trigger the qeued functions
// @website https://stackoverflow.com/a/7988536/938089?listening-for-youtube-event-in-javascript-or-jquery
function getFrameID(id) {
var elem = document.getElementById(id);
if (elem) {
if(/^iframe$/i.test(elem.tagName)) return id; //Frame, OK
// else: Look for frame
var elems = elem.getElementsByTagName("iframe");
if (!elems.length) return null; //No iframe found, FAILURE
for (var i=0; i<elems.length; i++) {
if (/^https?:\/\/(?:www\.)?youtube(?:-nocookie)?\.com(\/|$)/i.test(elems[i].src)) break;
}
elem = elems[i]; //The only, or the best iFrame
if (elem.id) return elem.id; //Existing ID, return it
// else: Create a new ID
do { //Keep postfixing `-frame` until the ID is unique
id += "-frame";
} while (document.getElementById(id));
elem.id = id;
return id;
}
// If no element, return null.
return null;
}
// Define YT_ready function.
var YT_ready = (function() {
var onReady_funcs = [], api_isReady = false;
/* @param func function Function to execute on ready
* @param func Boolean If true, all qeued functions are executed
* @param b_before Boolean If true, the func will added to the first
position in the queue*/
return function(func, b_before) {
if (func === true) {
api_isReady = true;
for (var i=0; i<onReady_funcs.length; i++){
// Removes the first func from the array, and execute func
onReady_funcs.shift()();
}
}
else if(typeof func == "function") {
if (api_isReady) func();
else onReady_funcs[b_before?"unshift":"push"](func);
}
}
})();
// This function will be called when the API is fully loaded
function onYouTubePlayerAPIReady() {YT_ready(true);}
// Load YouTube Frame API
(function() { //Closure, to not leak to the scope
var s = document.createElement("script");
s.src = "http://www.youtube.com/player_api"; /* Load Player API*/
var before = document.getElementsByTagName("script")[0];
before.parentNode.insertBefore(s, before);
})();
/@description实现YouTube JavaScript API的更简单方法
//@作者Rob W
//@global getFrameID(id)快速查找与给定id对应的iframe对象的方法。
//@global YT_ready(函数:函数[,布尔值:que_在开始时])
//@global onyoutublayerapiready()-用于触发QUED函数
//@网站https://stackoverflow.com/a/7988536/938089?listening-用于javascript或jquery中的youtube事件
函数getFrameID(id){
var elem=document.getElementById(id);
if(elem){
if(//^iframe$/i.test(elem.tagName))返回id;//Frame,确定
//其他:寻找框架
var elems=elem.getElementsByTagName(“iframe”);
如果(!elems.length)返回null;//未找到iframe,则失败
对于(var i=0;i,由于原点限制,您不能使用
元素。相反,请嵌入
并使用YouTube播放器API与帧通信
将您的函数onyotubeplayerready
和函数初始化(播放列表)
替换为以下内容(在中):
要使以前的代码正常工作,您必须加载另一个脚本。的内容基于我以前对的回答:
// @description Easier way to implement the YouTube JavaScript API
// @author Rob W
// @global getFrameID(id) Quick way to find the iframe object which corresponds to the given ID.
// @global YT_ready(Function:function [, Boolean:qeue_at_start])
// @global onYouTubePlayerAPIReady() - Used to trigger the qeued functions
// @website https://stackoverflow.com/a/7988536/938089?listening-for-youtube-event-in-javascript-or-jquery
function getFrameID(id) {
var elem = document.getElementById(id);
if (elem) {
if(/^iframe$/i.test(elem.tagName)) return id; //Frame, OK
// else: Look for frame
var elems = elem.getElementsByTagName("iframe");
if (!elems.length) return null; //No iframe found, FAILURE
for (var i=0; i<elems.length; i++) {
if (/^https?:\/\/(?:www\.)?youtube(?:-nocookie)?\.com(\/|$)/i.test(elems[i].src)) break;
}
elem = elems[i]; //The only, or the best iFrame
if (elem.id) return elem.id; //Existing ID, return it
// else: Create a new ID
do { //Keep postfixing `-frame` until the ID is unique
id += "-frame";
} while (document.getElementById(id));
elem.id = id;
return id;
}
// If no element, return null.
return null;
}
// Define YT_ready function.
var YT_ready = (function() {
var onReady_funcs = [], api_isReady = false;
/* @param func function Function to execute on ready
* @param func Boolean If true, all qeued functions are executed
* @param b_before Boolean If true, the func will added to the first
position in the queue*/
return function(func, b_before) {
if (func === true) {
api_isReady = true;
for (var i=0; i<onReady_funcs.length; i++){
// Removes the first func from the array, and execute func
onReady_funcs.shift()();
}
}
else if(typeof func == "function") {
if (api_isReady) func();
else onReady_funcs[b_before?"unshift":"push"](func);
}
}
})();
// This function will be called when the API is fully loaded
function onYouTubePlayerAPIReady() {YT_ready(true);}
// Load YouTube Frame API
(function() { //Closure, to not leak to the scope
var s = document.createElement("script");
s.src = "http://www.youtube.com/player_api"; /* Load Player API*/
var before = document.getElementsByTagName("script")[0];
before.parentNode.insertBefore(s, before);
})();
/@description实现YouTube JavaScript API的更简单方法
//@作者Rob W
//@global getFrameID(id)快速查找与给定id对应的iframe对象的方法。
//@global YT_ready(函数:函数[,布尔值:que_在开始时])
//@global onyoutublayerapiready()-用于触发QUED函数
//@网站https://stackoverflow.com/a/7988536/938089?listening-用于javascript或jquery中的youtube事件
函数getFrameID(id){
var elem=document.getElementById(id);
if(elem){
if(//^iframe$/i.test(elem.tagName))返回id;//Frame,确定
//其他:寻找框架
var elems=elem.getElementsByTagName(“iframe”);
如果(!elems.length)返回null;//未找到iframe,则失败
对于(var i=0;i,我现在使用它作为提示(涉及jQuery和requireJS,但更简短)
//提供YouTube iFrame的接口。
//在收到来自YouTube API的就绪响应后启动Player/SongValidator对象。
定义(['onyoutublayerapiready'],函数(){
"严格使用",;
var事件={
onApiReady:“onApiReady”
};
//此代码将触发onYouTubePlayerAPIReady
$(窗口)。加载(函数(){
$('script:first')。在($('')之前{
src:'https://www.youtube.com/iframe_api'
}));
});
返回{
就绪:函数(){
$(this.trigger)(events.onApiReady);
},
onApiReady:函数(事件){
$(this).on(events.onApiReady,event);
}
};
});
//API完全加载时将调用此函数。需要全局公开,以便YouTube可以调用它。
var onYouTubePlayerAPIReady=函数(){
"严格使用",;
require(['youtube-player-api-helper'],函数(ytPlayerApiHelper){
ytPlayerApiHelper.ready();
});
}
使用youtubePlayerApi.onApiReady订阅活动。作为提示,我现在使用它(包括jQuery和requireJS,但更简短)
//提供YouTube iFrame的接口。
//在收到来自YouTube API的就绪响应后启动Player/SongValidator对象。
定义(['onyoutublayerapiready'],函数(){
"严格使用",;
var事件={
onApiReady:“onApiReady”
};
//此代码将触发onYouTubePlayerAPIReady
$(窗口)。加载(函数(){
$('script:first')。在($('')之前{
src:'https://www.youtube.com/iframe_api'
}));
});
返回{
就绪:函数(){
$(this.trigger)(events.onApiReady);
},
onApiReady:函数(事件){
$(this).on(events.onApiReady,event);
}
};
});
//API完全加载时将调用此函数。需要全局公开,以便YouTube可以调用它。
var onYouTubePlayerAPIReady=函数(){
"严格使用",;
require(['youtube-player-api-helper'],函数(ytPlayerApiHelper){
ytPlayerApiHelper.ready();
});
}
使用youtubePlayerApi.onApiReady订阅此活动。我不是flash大师。您可以分享有关脚本的更多信息吗?如果代码在网页上下文中运行,权限问题会得到解决吗?让我添加一个
//Provides an interface to the YouTube iFrame.
//Starts up Player/SongValidator object after receiving a ready response from the YouTube API.
define(['onYouTubePlayerAPIReady'],function(){
'use strict';
var events = {
onApiReady: 'onApiReady'
};
//This code will trigger onYouTubePlayerAPIReady
$(window).load(function(){
$('script:first').before($('<script/>', {
src: 'https://www.youtube.com/iframe_api'
}));
});
return {
ready: function(){
$(this).trigger(events.onApiReady);
},
onApiReady: function(event){
$(this).on(events.onApiReady, event);
}
};
});
//This function will be called when the API is fully loaded. Needs to be exposed globally so YouTube can call it.
var onYouTubePlayerAPIReady = function () {
'use strict';
require(['youtube-player-api-helper'], function(ytPlayerApiHelper){
ytPlayerApiHelper.ready();
});
}