Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a Chrome Extension run code when on a certain url

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

like image 201
Tyler Chong Avatar asked Jan 05 '17 01:01

Tyler Chong


People also ask

How do I pin a browser extension?

Open the Extensions by clicking the puzzle icon next to your profile avatar. A dropdown menu will appear, showing you all of your enabled extensions. Each extension will have a pushpin icon to the right of it. To pin an extension to Chrome, click the pushpin icon so that the icon turns blue.

How do you program a Chrome extension?

Go to chrome://extensions in your Google Chrome browser. Check the Developer mode checkbox in the top right-hand corner. Click “Load Unpacked” to see a file-selection dialog. Select your extension directory.


1 Answers

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)

like image 191
neaumusic Avatar answered Sep 27 '22 23:09

neaumusic