Skip to content Skip to sidebar Skip to footer

Webnavigation.ondomcontentloaded Url Filter Does Not Match Dns Error Url

Reference to the answer for my previous question here. Briefly: When an error occurs in a navigation webRequest (e.g. a DNS lookup error), the URL to which the tab navigates is ava

Solution 1:

Your code does not work the way you desire, because the URL you are looking for does not contain pagedoesnotexist.com as part of the host. The URL on which the error occurred is part of the query, not the host.

Unfortunately, using the events.UrlFilter key queryContains appears to have bugs (I'm still looking into the behavior I'm seeing). I found the following modifications to your code to be effective:

var errorDomain = 'pagedoesnotexist.com';
var filter = {
  url:
  [
    //{urlPrefix: 'about:neterror'} // works// The simple RegExps in the following urlMatches have the// possibility to produce false positives on matching the// domain.  In other words, some other error URLs could match// this RegExp.  However, a more complex RegExp which would// prevent such false positive matches would depend on the// exact criteria you desire to use for matching.  For// instance, are you wanting to match sub-domains?  Only HTTP? // both HTTP and HTTPS?  Any protocol (e.g.  FTP)?
    {urlMatches: '^about:neterror\\?.*' + errorDomain + '.*'} // works.//{urlMatches: '.*pagedoesnotexist.com.*'} // works//{urlMatches: '.*page.*'} // works//{queryContains: 'pagedoesnotexist.com'} // Does NOT work (potentially a Firefox bug)//{queryContains: 'page'} // Does NOT work (potentially a Firefox bug)
  ]
}

functionlogOnDOMContentLoaded(details) {
  console.log("onDOMContentLoaded: " + details.url);
}

browser.webNavigation.onDOMContentLoaded.addListener(logOnDOMContentLoaded, filter);

Post a Comment for "Webnavigation.ondomcontentloaded Url Filter Does Not Match Dns Error Url"