我正在学习如何创建Chrome扩展程序.我刚开始开发一个来捕捉YouTube活动.我想将它与YouTube Flash播放器一起使用(稍后我将尝试使其与HTML5兼容).
manifest.json的:
{
"name": "MyExtension",
"version": "1.0",
"description": "Gotta catch Youtube events!",
"permissions": ["tabs", "http://*/*"],
"content_scripts" : [{
"matches" : [ "www.youtube.com/*"],
"js" : ["myScript.js"]
}]
}
Run Code Online (Sandbox Code Playgroud)
myScript.js:
function state() { console.log("State Changed!"); }
var player = document.getElementById("movie_player");
player.addEventListener("onStateChange", "state");
console.log("Started!");
Run Code Online (Sandbox Code Playgroud)
问题是控制台给了我"开始!" ,但没有"状态改变!" 当我播放/暂停YouTube视频时.
将此代码放入控制台时,它可以正常工作.我究竟做错了什么?
javascript google-chrome youtube-api google-chrome-extension content-script
我正在开发Chrome扩展程序.我希望解析"原始"Gmail邮件(当前查看的邮件)的内容.
我试图利用jQuery.load()如下
$(windows).load(function() { alert(GLOBALS); });
Run Code Online (Sandbox Code Playgroud)
并将其放在内容脚本中,但它也不起作用.我正在使用Chrome的开发人员工具,它会在调用时返回以下错误alert(GLOBALS);
未捕获的ReferenceError:未定义GLOBALS
虽然,在使用开发人员工具的控制台时,键入控制台GLOBALS会返回一个数组.
有关如何从内容脚本访问GLOBALS的任何线索?
我正在构建一个扩展程序,通过将gmail.js注入页面上下文,与Gmail集成并与Gmail集成,如下所示:https://github.com/KartikTalwar/gmail-chrome-extension-boilerplate/blob/master /content.js
这似乎是利用Google嵌入页面的一些全局变量的唯一明显方法.
所以现在,我需要回到扩展的一些功能.在正常情况下(从内容脚本操作),我会向后台脚本发送一条消息,但是甚至可以从选项卡本身的上下文中发送消息吗?
我正在开发chrome扩展.我成功加载了JavaScript文件,但问题是外部JavaScript(我已加载)无法调用内容脚本文件的功能,我的代码如下.
$(document).ready(function() {
$('.main_list').click(function()
{
$('.sub_list') .hide();
$(this) .parent() .children('.sub_list') .slideToggle("normal");
});
$('#click') .click(function()
{
$('.sub_list') .hide();
$(this) .parent() .parent() .children('.sub_list').slideToggle("normal");
});
$('#btnnewtask').click(function()
{
showdialog('http://localhost:51967/task.aspx');
});
$('#linknewtask').click(function()
{
showdialog('http://localhost:51967/task.aspx');
});
$('#btnnewcall').click(function()
{
showdialog('http://localhost:51967/call.aspx');
});
$('#linknewcall').click(function()
{
showdialog("http://localhost:51967/call.aspx");
});
$('#btnnewmeeting').click(function()
{
showdialog("http://localhost:51967/meeting.aspx");
});
$('#linknewmeeting').click(function()
{
showdialog("http://localhost:51967/meeting.aspx");
});
});
Run Code Online (Sandbox Code Playgroud)
Showdialog()是内容脚本中的函数.如下
function showdialog(url)
{
var xhr=new XMLHttpRequest();
xhr.onreadystatechange=function()
{
if (xhr.readyState==4 && xhr.status==200)
{
xmldoc=xhr.responseXML;
var js=getfile(getjavascript(xmldoc));
for(i=0;i<js.length;i++)
{
loadjscssfile(js[i],"js");
}
var css=getfile(getstylesheet(xmldoc))
for(i=0;i<css.length;i++)
{
loadjscssfile(css[i],"css");
}
document.file.push(
{"url":url,"css":css,"js":js});
document.getElementById("dialogcontainer3").
innerHTML=gethtmldocument(xmldoc);
document.getElementById("blacklayer").style.display="block";
document.getElementById("dialogcontainer3").style.display= …Run Code Online (Sandbox Code Playgroud) html google-chrome google-chrome-extension google-chrome-devtools