Categories
JavaScript Answers

How to make Chrome Extension run every page load with JavaScript?

Spread the love

Sometimes, we want to make Chrome Extension run every page load with JavaScript.

In this article, we’ll look at how to make Chrome Extension run every page load with JavaScript.

How to make Chrome Extension run every page load with JavaScript?

To make Chrome Extension run every page load with JavaScript, we call chrome.tabs.onUpdated.addListener with a callback to runs on every page load.

For instance, we write

chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
  if (changeInfo.status === "complete") {
    // ...
  }
});

to call chrome.tabs.onUpdated.addListener with a callback that runs on every page load.

If changeInfo.status is 'complete', then the page is loaded and we can do whatever we want after the page is loaded.

Conclusion

To make Chrome Extension run every page load with JavaScript, we call chrome.tabs.onUpdated.addListener with a callback to runs on every page load.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *