I created a chrome extension, the extension needs to get a variable from a script to use it in another context, i can access the variable using browser console but i can't access it by my extension using window.VARIABLE_NAME
const getCodeBtn= document.getElementById('get-code-btn');
async function getCode() {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: addCode,
})
}
//we need to add code in a website input
function addCode() {
const input = document.getElementById('some-id');
const btn = document.getElementById('some-id');
input.value = window.code; //window.code is undefined
console.log(window.code) // undefined
btn.click();
}
getCodeBtn.addEventListener('click', getCode)
I still can access the variable value in browser console
code; // 1235469