某些网址未调用内容脚本

lab*_*nth 1 google-chrome-extension

在我的manifest.xml中,我有如下内容脚本:

"content_scripts": [    
        {
            "matches": [
                "*://*/*"                
            ],
            "js": ["xyz.js"],
            "all_frames": true,
            "run_at": "document_idle"
        }
Run Code Online (Sandbox Code Playgroud)

几乎所有以http,https或以"file://"开头的URL开头的网址都会调用它.但对于我用pdf.js打开的pdf,url变成了:chrome-extension://namhfjepbaaecpmpgehfppgnhhgaflne/content/web/viewer.html?file=http%3A%2F%2Fwww.ifets.info%2Fjournals%2F10_4%2F9.pdf


在这些情况下,我不会调用内容脚本.这背后有什么原因吗?或者我没有正确使用内容脚本?

wOx*_*xOm 5

pdf.js是一个扩展,它使用chrome-extension://协议在自己的页面上打开pdf.内容脚本不支持此协议.原因是扩展使用特权API,因此被设计为通过内容脚本等与另一个扩展"劫持"隔离.

如果pdf.js是您自己的扩展的一部分,则可以手动将内容脚本添加到扩展程序自己的html页面(content/web/viewer.html在您的情况下):

<head>
    <script src="xyz.js"></script>
</head>
Run Code Online (Sandbox Code Playgroud)

PS而不是按照文档*://*/*使用.<all_urls>