且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Chrome内容脚本不会在about:空白页面中加载

更新时间:2023-12-05 07:50:58

更新:截至Chrome 37(2014年8月26日),您可以设置 match_about_blank flag Doc true $> c $ c>为 about:blank 页面触发



请参阅






$ b $ ***.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, or chrome-extension)...


In this case, you might be better off hijacking makewindow().