Opened 3 months ago

Closed 3 months ago

Last modified 3 months ago

#7384 closed change (fixed)

Polyfill browser.webRequest.ResourceType for Edge

Reported by: kzar Assignee: kzar
Priority: P2 Milestone: Adblock-Plus-for-Chrome-Opera-Firefox-next
Module: Platform Keywords:
Cc: sebastian, geo, greiner Blocked By:
Blocking: Platform: Edge
Ready: yes Confidential: no
Tester: Unknown Verified working: no
Review URL(s):

https://gitlab.com/eyeo/adblockplus/adblockpluschrome/merge_requests/51
https://gitlab.com/eyeo/adblockplus/adblockpluschrome/merge_requests/56

Description (last modified by kzar)

Background

Both Firefox and Chrome provide an Object browser.webRequest.ResourceType which lists the support resource types which can be used to filter webRequest events. Edge does not provide that, but does list the valid resource types when an listener is incorrectly created.

What to change

  • In adblockpluschrome/polyfill.js, if browser.webRequest.ResourceType isn't defined, attempt to create a listener for the browser.webRequest.onBeforeRequest event with an invalid resource type filter. Then attempt to obtain the list of valid resource types from the exception's message.

For example:

browser.webRequest.onBeforeRequest.addListener(details => {}, {urls:["<all_urls>"], types:["foo"]})

Results in the following exception on Edge 42.17134.1.0:

Error: Invalid value for argument 2. Property 'types': Value must be one of: [main_frame,sub_frame,stylesheet,script,image,object,xmlhttprequest,fetch,ping,other].

From that, browser.webRequest.ResourceType should look something like this:

{MAIN_FRAME: "main_frame",
SUB_FRAME: "sub_frame",
STYLESHEET: "stylesheet",
SCRIPT: "script",
IMAGE: "image",
OBJECT: "object",
XMLHTTPREQUEST: "xmlhttprequest",
FETCH: "fetch",
PING: "ping",
OTHER: "other"}
  • Modify any code which assumes browser.webRequest.ResourceType doesn't exist on Edge, for example in adblockpluschrome/lib/requestBlocker.js.
  • Modify webRequest listeners (e.g. in adblockpluschrome/ext/background.js) that we've so far avoided passing the types filter for, to use that instead of manually checking the event's type property.

Notes

  • Edge seems to provide the exception as a String, where as the other browsers provide it as an Object which contains a message property which references the String.
  • No need to handle them, but here's how the exception message looks on
    • Chrome 72.0.3626.119: Error at parameter 'filter': Error at property 'types': Error at index 0: Value must be one of csp_report, font, image, main_frame, media, object, other, ping, script, stylesheet, sub_frame, websocket, xmlhttprequest.
    • Firefox 64.0: Type error for parameter filter (Error processing types.0: Invalid enumeration value "foo") for webRequest.onBeforeRequest.

Hints for testers

  • Ensure request blocking works properly on Chrome (both new and old), Firefox and Edge.
  • Ensure that #7305 is still fixed.
  • Ensure there aren't any new exceptions thrown by the content scripts.

Change History (16)

comment:1 Changed 3 months ago by kzar

  • Description modified (diff)

comment:2 Changed 3 months ago by kzar

  • Platform changed from Unknown / Cross platform to Edge

comment:3 Changed 3 months ago by kzar

  • Blocking 7305 removed

comment:4 Changed 3 months ago by kzar

  • Description modified (diff)

comment:5 Changed 3 months ago by kzar

  • Description modified (diff)

comment:6 Changed 3 months ago by kzar

  • Description modified (diff)

comment:7 Changed 3 months ago by kzar

  • Description modified (diff)

comment:8 Changed 3 months ago by kzar

  • Owner set to geo

comment:9 Changed 3 months ago by greiner

  • Cc greiner added

comment:10 Changed 3 months ago by kzar

  • Owner changed from geo to kzar
  • Review URL(s) modified (diff)

comment:11 Changed 3 months ago by kzar

  • Status changed from new to reviewing

comment:12 Changed 3 months ago by abpbot

A commit referencing this issue has landed:
Issue 7384 - Polyfill webRequest.ResourceType and Object.values

comment:13 Changed 3 months ago by kzar

  • Description modified (diff)
  • Milestone set to Adblock-Plus-for-Chrome-Opera-Firefox-next
  • Resolution set to fixed
  • Status changed from reviewing to closed

comment:14 Changed 3 months ago by abpbot

comment:15 Changed 3 months ago by kzar

  • Description modified (diff)

comment:16 Changed 3 months ago by kzar

  • Review URL(s) modified (diff)
Note: See TracTickets for help on using tickets.