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
Add a ment  | 

1 Answer 1

Reset to default 7

The 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