content script file:
chrome.extension.sendMessage({ greetings: "hello from new page" }, function (response) {
console.log("response", response)
let storeData = response.store
var readyStateCheckInterval = setInterval(function () {
if (document.readyState === "complete") {
clearInterval(readyStateCheckInterval);
let th = document.getElementsByTagName('body')[0];
let injectSc = document.createElement('script');
let filePath = chrome.extension.getURL('src/inject/injectScript.js')
// check window log in filePath
injectSc.setAttribute('type', 'text/javascript');
injectSc.setAttribute('src', filePath);
th.appendChild(injectSc);
}
},100)
})
function sendTokens(user_token){
chrome.extension.sendMessage(user_token, function (response) {})
}
here in content script i was not able to get window object of the webPage (this is the limitation of content script , (https://developer.chrome.com/extensions/content_scripts) you cannot Use variables or functions defined by web pages or by other content scripts.) so i added one script tag in webpage and got window object access in injectScript file but now how do i use any method of content script or chrome.runtime.sendmessage form injectScript file. injectScript file
if (document.readyState === "complete" || document.readyState === "interactive"){
console.log("window from inject script",window);
let yajRex = new RegExp('example.xyz.com')
if(yajRex.test(window.location.href)){
let user_tokens= {
token1:window.paramValue,
token2:window.paramValue
}
console.log(user_tokens);
// sendTokens(user_tokens)
//getting undefined function error here
}}