如果我console.log('something');从弹出页面或其他任何脚本调用它,它可以正常工作.
但是,由于后台页面没有直接从弹出页面运行,因此它不包含在控制台中.
有没有办法让我可以console.log()在后台页面显示弹出页面的控制台?
有没有办法,从后台页面调用弹出页面中的一个函数?
我正在尝试为浏览器的Web扩展测试示例代码.但是,它不起作用.我检查了控制台的谷歌浏览器和Firefox.它不打印任何东西.以下是我的代码:
manifest.json:
{
"description": "Demonstrating webRequests",
"manifest_version": 2,
"name": "webRequest-demo",
"version": "1.0",
"permissions": [
"webRequest"
],
"background": {
"scripts": ["background.js"]
}
}
Run Code Online (Sandbox Code Playgroud)
background.js:
function logURL(requestDetails) {
console.log("Loading: " + requestDetails.url);
}
chrome.webRequest.onBeforeRequest.addListener(
logURL,
{urls: ["<all_urls>"]}
);
console.log("Hell o extension background script executed");
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
firefox-addon google-chrome-extension google-chrome-devtools firefox-developer-tools firefox-addon-webextensions
这是我的HTML:
<!doctype html>
<html>
<head>
<title>PassVault</title>
<link rel="stylesheet" type="text/css" href="stil.css">
<meta charset="utf-8">
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script type="text/javascript">
$(document).ready(function () {
$("div").css("border", "3px solid red");
});
</script>
</head>
<body>
<div id="rainbow"> </div>
<div id="loginBox">
<div id="welcome"> Dobrodošli, uporabnik! </div><br>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
文档加载后,它应该在我的所有div周围放置一个红色边框(HTML文件中有很多),但事实并非如此.我不明白这里有什么问题.jQuery都在同一个文件中,jQuery托管的链接由Google提供,也可以使用.
值得一提的是.html文件是由Google Chrome扩展程序browser_action的manifest.json文件调用的.所以,它以这种方式打开弹出窗口:
还值得一提的是,上面的图片只是Google提供的示例图片.这不是我的形象.我的div没有边框,jQuery没有改变它.
的manifest.json
....
"browser_action": {
"default_popup": "popupindex.html",
}
....
Run Code Online (Sandbox Code Playgroud)
我不知道这个弹出窗口会如何影响.js文件功能,但我确定它与此有关.
OP对答案的评论中
添加:在所有这些div之间添加边框只是我测试jQuery是否有效的方法.我将来需要jQuery来完成其他很多事情.它甚至不适用于这个简单的事情.
html javascript jquery google-chrome-extension content-security-policy