T
T
tipask2452020-10-26 03:12:10
JavaScript
tipask245, 2020-10-26 03:12:10

How to pass variable from input from popup.js to inject.js?

popup.html has an input and a button

<input type="text" id="numb" class="no">
<button id="sub" class="subsave">Start</button>

in popup.js I get the value of this input and send inject.js to the site page
var btn = document.getElementById("sub");
btn.addEventListener('click', start);
function start(e) {
       chrome.tabs.executeScript({
            code: "let inp = " + document.getElementById("numb").value,  
            allFrames: true
       }, function(result) {
           chrome.tabs.executeScript({file: "/js/inject.js", allFrames: true}, function(result) {
           });
       });
}

But when run in the console, it gives an error Uncaught TypeError: Cannot read property 'value' of null
What should I do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
acwartz, 2020-10-26
@acwartz

Popup plays by the same rules as any other page.
You need to wait for DOMContentLoaded and then bind the events and allow them to work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question