N
N
Nick_Apex2017-05-31 17:33:43
Google Chrome
Nick_Apex, 2017-05-31 17:33:43

How to make instant launch js from chrome extension?

For example:
An extension that will replace the content of placeholder.
If you do this in background.js,

function first() {
  var change = document.querySelector('input');
  change.placeholder = 'Вася, пиши тут';
};
first();

the browser will almost instantly load the script. BUT, if I have slow internet or something goes wrong and background.js is loaded before this placeholder is loaded, then at least nothing will happen. And if the code is complex, something will happen, but obviously not what was expected)).
If so, do it like this
function first() {
  var change = document.querySelector('input');
  change.placeholder = 'Вася, пиши тут';
};
window.addEventListener('load', first, false);

then background.js will be loaded only after the page is fully loaded.
Question: how to load the script immediately after the placeholder is loaded?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question