Firefox Extension: How to react to only one onload event in content script?

  firefox, firefox-addon, javascript

This is the code I’ve got in my content script at the moment and it works fine in most cases. It checks whether or not the user is currently visiting a privacy policy and sends that info to my background script.

window.addEventListener("DOMContentLoaded", (event) => {
    browser.runtime.sendMessage({
        isPrivacyPolicy: isPrivacyPolicy(),
    });
});

The problem is, on some pages which request data from other ones, the event get’s called multiple times. One time for each page data is requested from.

Is there a convinient way to wait for the page to fully load and then send one request to my background script?

Thank you!

Source: Ask Javascript Questions

LEAVE A COMMENT