简体   繁体   中英

how to execute content_script without clicking on the plugin icon in chrome plugin?

I want to execute my content_script without clicking on the plugin icon.

manifest.json

 { "short_name": "my plugin", "name": "vanilla Chrome Extension", "manifest_version": 2, "permissions": ["activeTab", "tabs", "<all_urls>", "webNavigation"], "version": "0.0.1", "browser_action": { "default_popup": "popup.html", "default_title": "my plugin" }, "content_scripts": [ { "matches": ["<all_urls>"], "css": ["content-script.css"], " js ": ["content-script.js"], "run_at": "document_end" } ] }

I also try document_idel and document_start

content-script.js

 console.log("inside plugin script"); document.querySelectorAll("h1").style.backgroundColor = "#c1c1c1";

I try to find out from docs but can't figure out what to do

as @wOxxOm commented on my question, in my manifest.json content_scripts section I leave space before and after "js" when I remove those spaces it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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