简体   繁体   English

内容脚本仅在页面加载(和重新加载)时执行

[英]Content script only executed on page load (& reload)

I would like to run a content script on the site di.se . 我想在站点di.se上运行内容脚本。 However, my issue is that it's only executed on the initial page load - not on links clicks (eg articles). 但是,我的问题是,它仅在初始页面加载时执行-而不是在链接点击(例如文章)上执行。

I know there are some similar threads out there, but they suggest that the page alters its URL by the window.history.pushState API, which doesn't seems to be the case here, as far as I can tell. 我知道那里有一些类似的线程,但是它们建议页面通过window.history.pushState API更改其URL,据我所知,这里似乎不是这种情况。

TL;DR: I need your help figuring out why the content script doesn't execute on page links. TL; DR:我需要您的帮助,弄清楚为什么内容脚本不能在页面链接上执行。

manifest.json manifest.json

{
    "manifest_version": 2,

    "name": "test",
    "description": "test",
    "version": "0.1",

    "browser_action": {
        "default_icon": "icon.png"
    },

    "permissions": [
        "activeTab"
    ],

    "content_scripts": [
        {
          "matches": ["http://www.di.se/*"],
          "js": ["jquery-1.11.3.min.js", "script.js"]
        }
    ]
}

script.js script.js

alert('test');

The site uses frames as you can see in the Inspector. 该站点使用框架,如您在检查器中看到的那样。

To autoinsert the content script into all frames add "all_frames": true as per the documentation : 要将内容脚本自动插入所有框架中,请按照文档添加"all_frames": true

"content_scripts": [{
    "matches": .........,
    "js": ..............,
    "all_frames": true
}]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM