Chrome内容脚本不会在about:空白页面中加载 [英] Chrome content script does not load in about:blank page
问题描述
我正在开发一个Chrome扩展程序,它将根据以下清单加载内容脚本:
content_scripts:[
{
匹配:[< all_urls> ],
js:[scripts / namespace / namespace.js,
scripts / log / Logger.js]
run_at:document_start,
all_frames:true
}
]
有一个模型网站其HTML代码是:
< html>
< head>
< script language = javascript>
var test;
函数makewindow(){
test = window.open('mywin');
test.window.document.write(< html>< body>< A onclick = window.close(); href =>点击我关闭< / A>);
test.window.document.write(----< / body>< / html>);
}
< / script>
< / head>
< body>
< a href =onclick =makewindow(); return false; >点击我启动外部窗口< / a>
< / body>
< / html>
如果我点击A链接并运行 makewindow
函数并弹出一个新窗口。
新窗口的URL是 about:blank
,并且内容脚本未加载到此新窗口中。
如何在新窗口中加载内容脚本?
更新:截至Chrome 37(2014年8月26日),您可以设置 match_about_blank
flag Doc 至 true $> c $ c>为
页面触发
$ b $ stackoverflow.com/a/36329205\">alib_15's answer 。 b
适用于37版之前的Chrome: 您无法在 about:blank
页面。
<这是因为
about:
不是允许的方案之一。从 Chrome扩展程序匹配模式:
匹配模式本质上是一个以允许的模式开头的URL(
http
,https
,文件
,ftp
或chrome-extension
)...
在这种情况下,您可能最好是劫持 makewindow()
。
I am developing a Chrome extension which will load content script according to the following manifest:
"content_scripts" : [
{
"matches" : [ "<all_urls>" ],
"js" : [ "scripts/namespace/namespace.js",
"scripts/log/Logger.js"]
"run_at" : "document_start",
"all_frames" : true
}
]
There is a mockup site whose HTML is:
<html>
<head>
<script language=javascript>
var test;
function makewindow() {
test=window.open('mywin');
test.window.document.write("<html><body><A onclick=window.close(); href= > click Me to Close</A>");
test.window.document.write(" ---- </body></html>");
}
</script>
</head>
<body>
<a href="" onclick="makewindow();return false;" >Click me to launch the external Window</a>
</body>
</html>
If I click the A link and it will run makewindow
function and pops up a new window.
The URL of new window is about:blank
, and content script is not loaded in this new window.
How to load content script in this new window?
Update: As of Chrome 37 (August 26, 2014), you can set the match_about_blank
flagDoc to true
to fire for about:blank
pages.
See alib_15's answer below.
For Chrome prior to version 37:
You cannot load a Chrome content script (or userscript) on about:blank
pages.
This is because about:
is not one of the "permitted schemes". From chrome extensions Match Patterns:
A match pattern is essentially a URL that begins with a permitted scheme (
http
,https
,file
,ftp
, orchrome-extension
)...
In this case, you might be better off hijacking makewindow()
.
这篇关于Chrome内容脚本不会在about:空白页面中加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!