Opened on 10/27/2016 at 10:20:45 AM

Closed on 02/06/2018 at 12:23:00 PM

Last modified on 03/22/2018 at 02:00:59 PM

#4579 closed change (fixed)

Target promise-based browserext API

Reported by: kzar Assignee: mjethani
Priority: P3 Milestone: Adblock-Plus-3.0.3-for-Chrome-Opera-Firefox
Module: Platform Keywords:
Cc: sebastian, oleksandr, greiner Blocked By: #4551, #4783, #5028
Blocking: #4580 Platform: Unknown / Cross platform
Ready: no Confidential: no
Tester: Ross Verified working: yes
Review URL(s):

https://codereview.adblockplus.org/29573892/
https://codereview.adblockplus.org/29678657/

Description (last modified by kzar)

Background

We want to target the browserext standard instead of the Chrome extension API. This should hopefully mean Edge and in the future Gecko can be supported without pollyfills.

What to change

  • Add a polyfill for the Chrome extension to add browserext compatibility, adding the browser namespace, wrapping asynchronous APIs to use promises and mapping the others directly. (See this existing polyfill
  • Replace any other use of the Chrome APIs with the with the browserext API.

Attachments (0)

Change History (37)

comment:1 Changed on 10/27/2016 at 10:21:16 AM by kzar

  • Blocked By 4551 added; 4511 removed

comment:2 Changed on 10/27/2016 at 10:23:07 AM by kzar

  • Description modified (diff)

comment:3 Changed on 10/27/2016 at 03:41:04 PM by kzar

  • Description modified (diff)
  • Summary changed from Remove ext compatibility layer, target browser extension API to Target the browser extension API

comment:4 Changed on 10/27/2016 at 03:43:33 PM by sebastian

  • Priority changed from Unknown to P3
  • Ready set

comment:5 Changed on 10/27/2016 at 03:46:11 PM by kzar

  • Blocking 4580 added

comment:6 Changed on 10/27/2016 at 03:48:30 PM by kzar

  • Summary changed from Target the browser extension API to Target the browserext API

comment:7 Changed on 11/21/2016 at 04:27:43 PM by kzar

  • Cc oleksandr added
  • Owner set to kzar

comment:8 Changed on 01/10/2017 at 07:43:53 AM by kzar

  • Blocked By 4783 added

comment:9 Changed on 01/11/2017 at 05:55:07 PM by greiner

  • Cc greiner added

comment:10 Changed on 02/24/2017 at 11:55:20 PM by sebastian

Giving it a second though (and having a go myself) it seems too early to target (and polyfill) the Promise based API. As of now, neither Chrome nor Microsoft Edge supports Promises with their API. Only Firefox does, which also optionally accepts callbacks. As a result callbacks (as opposed to Promises) are the common denominator of all targeted browsers. Implementing a polyfill that allows us to use Promises will add complexity and overhead.

But what I think we should already do is replacing all occurrences of chrome with browser, aliasing browser = chrome on Chrome. We already did it the other way around in the edge branch (#3695), and we might need it for Firefox/WebExtensions as well. However, it feels backwards, to keep using the chrome.* namespace, while this code runs on other browser, and browser is going to be standardized.

comment:11 Changed on 02/27/2017 at 11:40:43 AM by kzar

I already made a lot of progress towards targeting the browser API, if you're curious to have a look here's my branch. It has been a while since I looked at it but IIRC I didn't quite finish, and also I planned to try using a lighter weight polyfill that Wladimir suggested. (Also I need to rebase again...) I did have mostly everything working however.

But I kind of agree with you, I think it might well be a little early to make the switch.

comment:12 Changed on 03/22/2017 at 07:41:44 AM by kzar

  • Owner kzar deleted

Unassigned myself since I don't have the time to continue working on this currently and as per the above discussion we're not sure if it's the right time to make the switch anyway.

comment:13 Changed on 03/22/2017 at 09:11:37 AM by sebastian

  • Blocked By 5028 added

comment:14 Changed on 03/22/2017 at 09:15:40 AM by sebastian

  • Ready unset

I moved the part about using browser.* with callbacks (instead of promises), for now, into #5028.

comment:15 Changed on 03/22/2017 at 09:42:04 AM by sebastian

  • Summary changed from Target the browserext API to Target promise-based browserext API

comment:16 Changed on 10/17/2017 at 04:52:13 PM by mjethani

  • Owner set to mjethani
  • Review URL(s) modified (diff)

comment:17 Changed on 10/17/2017 at 04:52:23 PM by mjethani

  • Status changed from new to reviewing

comment:18 Changed on 10/18/2017 at 12:10:35 AM by abpbot

A commit referencing this issue has landed:
Issue 4579 - Promisify APIs

comment:19 Changed on 10/18/2017 at 12:11:52 AM by mjethani

  • Milestone set to Adblock-Plus-for-Chrome-Opera-Firefox-next
  • Resolution set to fixed
  • Status changed from reviewing to closed

comment:20 Changed on 10/18/2017 at 01:54:58 AM by mjethani

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:21 Changed on 10/18/2017 at 01:55:23 AM by mjethani

  • Milestone Adblock-Plus-for-Chrome-Opera-Firefox-next deleted

comment:22 Changed on 10/18/2017 at 11:08:20 AM by kzar

I notice a whole bunch of exceptions in the background console since this landed:

Uncaught (in promise) {message: "The message port closed before a response was received."}
func.call.result @ polyfill.js:80
sendResponseAndClearCallback @ extensions::messaging:415
disconnectListener @ extensions::messaging:439
EventImpl.dispatchToListener @ extensions::event_bindings:403
publicClassPrototype.(anonymous function) @ extensions::utils:140
EventImpl.dispatch_ @ extensions::event_bindings:387
EventImpl.dispatch @ extensions::event_bindings:409
publicClassPrototype.(anonymous function) @ extensions::utils:140
dispatchOnDisconnect @ extensions::messaging:376

comment:23 Changed on 10/19/2017 at 12:34:54 AM by mjethani

It seems that when we call runtime.sendMessage with a callback, and we don't get a response, Chrome considers that to be something worth reporting in runtime.lastError

We may have to handle this case in the wrapper, since it's usually not an error the caller is interested in.

comment:24 Changed on 10/20/2017 at 01:26:33 AM by abpbot

A commit referencing this issue has landed:
Issue 4579 - Wrap rejection reason in Error object

comment:25 Changed on 10/20/2017 at 01:50:51 AM by abpbot

A commit referencing this issue has landed:
Issue 4579 - Ignore runtime.lastError caused by wrapper

comment:26 Changed on 10/26/2017 at 04:00:50 PM by abpbot

A commit referencing this issue has landed:
Issue 4579 - Do not wrap non-existent APIs

comment:27 follow-up: Changed on 01/09/2018 at 09:59:48 AM by abpbot

A commit referencing this issue has landed:
Issue 4579 - Wrap runtime.onMessage

comment:28 in reply to: ↑ 27 Changed on 01/24/2018 at 02:45:12 PM by kzar

Replying to abpbot:

A commit referencing this issue has landed:
Issue 4579 - Wrap runtime.onMessage

This last commit is causing a couple of linting errors Manish:

adblockpluschrome/polyfill.js

  133:39  error  'hasListener' is assigned a value but never used  no-unused-vars
  160:15  error  Unsafe usage of ThrowStatement                    no-unsafe-finally
Last edited on 01/24/2018 at 02:47:34 PM by kzar

comment:29 Changed on 01/24/2018 at 04:08:33 PM by mjethani

  • Review URL(s) modified (diff)
  • Status changed from reopened to reviewing

comment:30 Changed on 01/24/2018 at 05:59:00 PM by abpbot

A commit referencing this issue has landed:
Issue 4579 - Fix ESLint errors

comment:31 Changed on 01/24/2018 at 06:00:31 PM by mjethani

  • Resolution set to fixed
  • Status changed from reviewing to closed

comment:32 Changed on 01/26/2018 at 04:40:34 PM by abpbot

A commit referencing this issue has landed:
Issue 4579 - Fix ESLint errors

comment:33 Changed on 02/01/2018 at 07:37:21 PM by mjethani

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:34 Changed on 02/01/2018 at 07:41:21 PM by mjethani

Changeset 7247eb4632fa has caused a regression due to the way the wrappers are implemented. We expect tabs.insertCSS to throw an error, which it does, but that error is turned into a promise rejection by the wrapper. We could simply handle the rejection, but that would be asynchronous and would cause the code in lib/cssInjection.js to become more complicated, aside from being inconsistent with Firefox.

The wrapper should also throw an error if the wrapped function throws an error.

I have logged #6343 for this.

Last edited on 02/01/2018 at 08:30:26 PM by mjethani

comment:35 Changed on 02/06/2018 at 12:17:48 PM by abpbot

A commit referencing this issue has landed:
Issue 4579, 6343 - Let errors from wrapped API calls bubble up

comment:36 Changed on 02/06/2018 at 12:23:00 PM by mjethani

  • Milestone set to Adblock-Plus-for-Chrome-Opera-Firefox-next
  • Resolution set to fixed
  • Status changed from reopened to closed

comment:37 Changed on 03/22/2018 at 02:00:59 PM by Ross

  • Tester changed from Unknown to Ross
  • Verified working set

Done. Didn't see any of the errors described above. And using browser.runtime.sendMessage (for example) in the console works.

ABP 3.0.2.1983
Firefox 51 / 58 / Windows 10
Chrome 49 / 65 / Windows 7
Opera 36 / 51 / Windows 7

Add Comment

Modify Ticket

Change Properties
Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from mjethani.
 
Note: See TracTickets for help on using tickets.