admin管理员组文章数量:1302352
I'm trying to build a Chrome Extension that needs to send a POST request to a server when the user is on a certain url/path.
I have that part working, except the code I have right now only runs when I click on the icon of my Chrome Extension, how would I make the code run every time I'm on a certain url?
I also need data stored in chrome.storage to be accessible in the code that runs every time aswell
I'm trying to build a Chrome Extension that needs to send a POST request to a server when the user is on a certain url/path.
I have that part working, except the code I have right now only runs when I click on the icon of my Chrome Extension, how would I make the code run every time I'm on a certain url?
I also need data stored in chrome.storage to be accessible in the code that runs every time aswell
Share asked Jan 5, 2017 at 1:56 Tyler ChongTyler Chong 7203 gold badges12 silver badges25 bronze badges 3- Is your code in a content script? Content scripts run in the background of web pages. – Loaf Commented Jan 5, 2017 at 2:02
- chrome.storage may only be accessible via the background page. you will need to sendMessage to the background page, then sendMessage back. I remember having an issue which was resolved by including the third param (true) – neaumusic Commented Jan 5, 2017 at 2:09
- Possible duplicate of Chrome Extension run for a specific page – Tyler Chong Commented Jul 4, 2019 at 1:28
1 Answer
Reset to default 7The answer is to use a content script
Specify the matching url in your manifest.
A background page is always running, but the content script is only injected on specific pages (you can specify before/after load end)
本文标签: javascriptHow to make a Chrome Extension run code when on a certain urlStack Overflow
版权声明:本文标题:javascript - How to make a Chrome Extension run code when on a certain url - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741697626a2393099.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论