CarsonSlovoka/chrome

How to debug

Closed this issue · 2 comments

How to debug
  1. go to chrome://extensions/, and then click Service Worker
    image

  2. Right-click on your icon, click Inspect popup on your browser, and then find your source start debugging.

image

  1. use the chrome.scripting.executeScript.runtime function

and you can directly inspect (F12) on the webpage. Click the Console tab, it will show you a source id(for example VM87:3) You can click it, and then start debugging.

chrome.storage.sync.set({msg: cmdName}) // You can not get the context on the function, so using the Storage API to help you. // https://developer.chrome.com/docs/extensions/reference/storage/
chrome.tabs.query({active: true, currentWindow: true}).then(([tab])=>{
chrome.scripting.executeScript({
target: {tabId: tab.id},
function: () => {
chrome.storage.sync.get(['msg'], ({msg})=> {
console.log(`${msg}`)
alert(`Command: ${msg}`)
})
}
})
})
image

Getting variables outside executeScript in chrome extension: https://stackoverflow.com/a/68622659/9935654