0

maybe someone can explain me how to resolve this problem:

For example I have this code:

let btn = document.getElementById('defbtn');

if (btn != null) {
    btn.onclick =  function(el) {
        chrome.tabs.query({active:true, currentWindow: true}, function(tabs) {
            chrome.tabs.executeScript(
                tabs[0].id,
                {code: "var textP = document.evaluate( 'any_xpath_here', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue.innerHTML;"}
            );
        });
        
        // How to get value from textP? To execute for example     alert(textP);
    }
}

How can I access textP value from chrome extension or how can I save textP in a chrome extension variable?

Lee
  • 1
  • 1
    use Chrome Message API to communicate with your extension. (https://developer.chrome.com/docs/extensions/mv3/messaging/) – mrtechtroid May 11 '22 at 02:24
  • Remove `var textP=` and use the parameter in the callback, see [these examples](https://stackoverflow.com/a/67227376/). – wOxxOm May 11 '22 at 02:51

0 Answers0