Newbie, can't find a way for this code to work inside webRequest.onBeforeRequest due return

52 views Asked by At

EDIT: The problem here was the third line not being written the proper way and it wouldn't work either way. browser.notifications did what I needed.

This is what I currently have. It needs to cancel the request and notify why it has been cancelled. The request cancellation part works fine, however, I am not sure where the notification code should go. I tried by adding innerhtml inside function, but that breaks the code.

browser.webRequest.onBeforeRequest.addListener(
    function() {
    getElementsByTagName(body).innerhtml = '<p>Test</p>'; // the problem
        return {cancel: true};
    },
    {
        urls: ["(links)"]
    },
    ["blocking"]
);
2

There are 2 answers

2
Daniel Murawsky On BEST ANSWER

In addition to what Paul said, I think you probably want body to be a string:

document.getElementsByTagName("body")[0].innerhtml
3
Paul On

Couple things in there. First, getElementsByTagName is not a function on the global scope, it's on the document scope. Second, it returns an array of elements (even if it's an array of just one 'body' element). So what you might be trying to do is this:

browser.webRequest.onBeforeRequest.addListener(
    function() {
    document.getElementsByTagName("body")[0].innerhtml = '<p>Test</p>';
        return {cancel: true};
    },
    {
        urls: ["(links)"]
    },
    ["blocking"]
);