Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: onDoubleClicked for browserAction #196

Closed
stefanvd opened this issue Apr 12, 2022 · 6 comments
Closed

Proposal: onDoubleClicked for browserAction #196

stefanvd opened this issue Apr 12, 2022 · 6 comments
Labels
enhancement Enhancement or change to an existing feature

Comments

@stefanvd
Copy link

stefanvd commented Apr 12, 2022

Motivation

The use of Manifest V2 to Manifest V3 diminishes the good web experience. And create some inconvenience for existing users using the DoubleClick action on my browser extensions.

The currently available listener for a click:
browser.browserAction.onClicked.addListener(listener)

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/browserAction/onClicked

Due to the lack of a support timer (setTimeout and setInterval) in the service worker, there is no way to detect the user double-clicking. Even with the chrome.alarms.create("MyDelay", {when: Date.now() + 1 * 3000}) you can get it to work in seconds. However, the documentation said once you have published the Chrome extension, the actual interval will be rounded up to 1 minute even if you set a smaller value like 3 seconds (3000ms).
Source: https://developer.chrome.com/docs/extensions/reference/alarms/#method-create

The following browser extensions use the double click function:

Proposal

browser.browserAction.onDoubleClicked.addListener(listener)
or allow the chrome.alarms.create("MyDelay", {when: Date.now() + 1 * 3000}) for seconds.

It will extend the user experience for desktop and mobile web browsers. And create a convenient way for mobile users to get more control on a small device. Such as opening the options page of that browser extension.

@stefanvd
Copy link
Author

@dotproto
Copy link
Member

dotproto commented Apr 12, 2022

Due to the lack of a support timer (setTimeout and setInterval) in the service worker, there is no way to detect the user double-clicking.

setTimeout and setInterval are exposed in workers, but they are only valid for the duration of that worker. As with any other JS context, all timers created in a worker context are cleared when that context is terminated. As such, there are many situations where JS timers may not behave as expected, but I don't think this is one of them. The timeout for a double click handler is short enough that setTimeout still works as expected.

Here's a functional demo of a double click action in an MV3 extension that's heavily cribbed from Turn Off the Lights.

@stefanvd
Copy link
Author

That is my code (see my Github profile icon). That is conflicting information, because according to this article it is recommended to move away from setInterval.

Moving from timers to alarms
It's common for web developers to perform delayed or periodic operations using the setTimeout or setInterval methods. These APIs can fail in service workers,

Source: https://developer.chrome.com/docs/extensions/mv3/migrating_to_service_workers/#alarms

I did move to chrome.alarms.onAlarm.addListener API. And tested the development unpacked Chrome extension:
https://github.com/turnoffthelights/Turn-Off-the-Lights-Chrome-extension/blob/manifest-v3/src/js/background.js#L290
However, in my research, this code will not work in the Chrome extension package version according to that article. Once you've published the Chrome extension, the actual interval will be rounded up to 1 minute even if you set a smaller value like 250 milliseconds (0.004166 minutes).

Thank you. It is good to hear from you @dotproto that the current manifest v2 doubleclick code will not affect this issue for the service worker manifest v3.
However, the suggestion of the proposal is open to further shaping the browser extension ecosystem. That is easy for users and developers.

@Rob--W
Copy link
Member

Rob--W commented Apr 14, 2022

This was discussed during today's WECG meeting. The meeting notes are in the linked PR and will be merged with the repo within two weeks.

Stefan - it seems that you're primarily interested in a new API because of the belief that setTimeout cannot be relied on. That is not correct. While it's true that Service workers (and event pages) can shut down at inconvenient times, any reasonable implementation would not do so shortly after the user clicks the extension button. In other words, setTimeout with a small delay should work reliably.

@stefanvd
Copy link
Author

The proposal for the new API would be useful to reduce the code size. And add some new capabilities to improve the web experience.
For example. On mobile, you have 'single tap', 'long press', but no right-click. And the new 'double tap' which can create a new way for different functionality. Such as here on my browser extension, double-tap the lamp button, which opens a mini settings panel.

As I mentioned before, it is good to hear that the smaller setTimeout won't break this double click function in the manifest v3 service worker.

@Rob--W
Copy link
Member

Rob--W commented Apr 27, 2022

I'm closing this issue because we have discussed this topic and decided to not implement the requested method, as explained at the "Proposal: onDoubleClicked for browserAction" section of https://github.com/w3c/webextensions/blob/main/_minutes/2022-04-14-wecg.md.

While "Long press" could potentially be an alternative on mobile to double-click on desktop, it does not address the mentioned "affordance" issue, i.e. there not being a way for the user to know that long-press/double-click doing anything.

@Rob--W Rob--W closed this as completed Apr 27, 2022
@Rob--W Rob--W added the enhancement Enhancement or change to an existing feature label Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement or change to an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants