Last active
August 22, 2024 14:01
-
-
Save dance2die/d05924be83c6be1b20ba94206ff2beb0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chrome.tabs.query( | |
{ active: true, windowId: chrome.windows.WINDOW_ID_CURRENT }, | |
function(tabs) { | |
const { id: tabId } = tabs[0].url; | |
let code = `document.querySelector('h1')`; | |
// http://infoheap.com/chrome-extension-tutorial-access-dom/ | |
chrome.tabs.executeScript(tabId, { code }, function (result) { | |
// result has the return value from `code` | |
}); | |
} | |
); |
did you later find a solution?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting a Cannot read property 'query' of undefined error, here is the code I'm using it with please help me, the stackoverflow says that it has to be in the popup script and it is in it so I'm at loss as to why ti won't work...
popup.js
let changeColor = document.getElementById("changeColor");
chrome.storage.sync.get("color", ({ color }) => {
changeColor.style.backgroundColor = color;
});
changeColor.addEventListener("click", async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: CheckCryptoCurrencyValue,
});
});
function CheckCryptoCurrencyValue(){
chrome.storage.sync.get("color", ({ color }) => {
document.body.style.backgroundColor = color;
});
chrome.tabs.query(
{ active: true, windowId: chrome.windows.WINDOW_ID_CURRENT },
function(tabs) {
const { id: tabId } = tabs[0].url;
}