javascript - Chrome Extension - Run content script only when button is clicked -


i've had look, can't seem find , answer question (well, 1 works me anyway).

i've made chrome extension should run code that's in content script on click of icon only, runs page loads. there way prevent happening? none of possible strings can enter run_at cater this.

here example code in both scripts:

content script:

function runit() {     console.log('working'); } runit(); 

background.js:

chrome.browseraction.onclicked.addlistener(function(activetab) {     chrome.tabs.executescript(null, {file: "content.js"}); }); 

it log 'working' page loads, , each button click after that. there way stop running page loads?

thanks in advance contributions.

the browseraction.onclicked code in background page want. if want stop content.js running content script on page load, don't include content script in manifest.

specifically, in manifest.json file, have lines this:

"content_scripts": [   {     "matches": ["*://*/*"],     "js": ["content.js"]   } ], 

simply remove lines, , script stop running on page load, while click listener code continue working.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -