1

I`m just trying to get searchRecord variable as a callback.

Here is my script:

chrome.tabs.executeScript(null, {
    code: 'var script = document.createElement("script");\
        script.type = "text/javascript";\
        script.textContent = \
        "var column = new nlobjSearchColumn(`name`);\
        var searchRecord = nlapiSearchRecord(`subsidiary`, null, null, column);\
        console.log(searchRecord)";\
        document.head.appendChild(script);
        script.textContent'
  }, function (results) {
    console.log(results)
  })

The result of a script is the last expression being evaluated, but it returns as a string:

"var column = new nlobjSearchColumn(`name`);        var searchRecord = nlapiSearchRecord(`subsidiary`, null, null, column);     console.log(searchRecord)"

I appreciate for helps!

  • `script.textContent` is a plain string. It doesn't run the script. To pass a value from the [page context](https://stackoverflow.com/a/9517879) into the content script context you'll have to use DOM CustomEvent, and chrome.runtime messaging, see [Access global js variables](https://stackoverflow.com/a/46870005) (note, in your case it'll be popup script instead of "iframe script" mentioned in the answer; and no need for chrome.tabs.getCurrent too). – wOxxOm Jun 18 '18 at 16:17
  • It works for me! thank you so much. – Andre Carvalho Jun 23 '18 at 18:22

0 Answers0