Skip to content

Improve support for mobile Firefox - #7480

Merged
fregante merged 14 commits into
refined-github:mainfrom
INSANEMODE:pr-mobile-options
Jun 24, 2024
Merged

fregante merged 14 commits into
refined-github:mainfrom
INSANEMODE:pr-mobile-options

Conversation

@INSANEMODE

Copy link
Copy Markdown
Contributor
  1. No relevant issue found

Description

This change is made to detect if the user is on a mobile platform (ios or android), instead of just looking for mobile Safari, or explicitly checking for user agents of mobile browsers.

Mobile safari, and other mobile browsers like Kiwi and Firefox for Android do not support context menus.
This change allows android browsers to access the options page.

getPlatformInfo seems to have fairly wide browser support, so it should be fine to use, instead of checking the user agent, like webext-detect-page does.

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

This method is used, because webext-detect-page does not seem to have functions to detect mobile browsers other than Safari.

This has only been tested on Firefox for android, and Firefox on windows. Kiwi on android should behave similarly, but i do not have an ios device to test mobile Safari.

Test URLs

Affects browser action button on mobile browsers, not URLs.

Screenshot

Screenshot 2024-06-23 044312

@fregante fregante left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I think the detection should look like "does this device have context menus"? This should probably also cover iPadOS. Ideally the chrome API can answer this question, but further exploration would be needed.

Comment thread source/background.ts Outdated
{
// GHE support
addPermissionToggle();
addPermissionToggle();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, i don't believe browser.contextMenus is defined on browsers that don't support them, so maybe a check to see if it is undefined or not could be useful, if there isn't a chrome api solution available?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That appears to be accurate: fregante/webext-permission-toggle#26

So you can just drop the mobile/safari check and replace it with !chrome.contextMenus

addPermissionToggle has its own check inside so this specific change isn't needed here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following error gets thrown on Firefox for android with the doesBrowserActionOpenOptions check removed on addPermissionToggle

00:13:02.267 Uncaught Error: webext-permission-toggle requires the `contextMenus` permission
    addPermissionToggle moz-extension://24fb74ed-aa72-4132-a59d-33a31291dced/assets/background.js:5183
    <anonymous> moz-extension://24fb74ed-aa72-4132-a59d-33a31291dced/assets/background.js:5857
    <anonymous> moz-extension://24fb74ed-aa72-4132-a59d-33a31291dced/assets/background.js:5961
    <anonymous> moz-extension://24fb74ed-aa72-4132-a59d-33a31291dced/assets/background.js:5963
background.js:5183:15
    addPermissionToggle moz-extension://24fb74ed-aa72-4132-a59d-33a31291dced/assets/background.js:5183
    <anonymous> moz-extension://24fb74ed-aa72-4132-a59d-33a31291dced/assets/background.js:5857
    <anonymous> moz-extension://24fb74ed-aa72-4132-a59d-33a31291dced/assets/background.js:5961
    <anonymous> moz-extension://24fb74ed-aa72-4132-a59d-33a31291dced/assets/background.js:5963

This prevents the action button from doing anything when pressed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking 🙏

What does the permissions array looks like there? The getter should return the manifest as is, is Firefox altering the manifest and removing the permission that does exist in the manifest?

Can you try console.log(chrome.runtime.getManifest())?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@INSANEMODE INSANEMODE Jun 24, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on firefox for android, the contextMenus permission isn't a valid permission, so it is just seems to ignore it if it is in the manifest.

Screenshot 2024-06-24 005921

Screenshot 2024-06-24 010001

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-06-24 010125

@fregante fregante changed the title change doesBrowserActionOpenOptions detect mobile platforms Simplify opening the options on mobile browsers other than Safari Jun 24, 2024
@fregante fregante changed the title Simplify opening the options on mobile browsers other than Safari Simplify opening the options on mobile browsers Jun 24, 2024
@fregante fregante added the meta Related to Refined GitHub itself label Jun 24, 2024

@fregante fregante left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good here, I'll send a PR to the other package and then publish it. It can then be installed here and merged

@fregante

Copy link
Copy Markdown
Member

@fregante fregante added firefox Related to Firefox only mobile bug and removed meta Related to Refined GitHub itself labels Jun 24, 2024
@fregante fregante changed the title Simplify opening the options on mobile browsers Improve support for mobile Firefox Jun 24, 2024
@fregante

Copy link
Copy Markdown
Member

I just realized, if addPermissionToggle was throwing an error, every feature that depended on the background script, including options migrations, etc, were broken until now. So this PR would actually fix a user-facing bug.

@INSANEMODE

Copy link
Copy Markdown
Contributor Author

Done fregante/webext-permission-toggle@v5.0.2 (release)

Does it work in both FirefoxAndroid and Kiwi?

Yep, it works on firefox for android with that change.

Attempted to load it on kiwi, and it looks like it can't install the extension at the moment, probably due to this issue. https://github.com/kiwibrowser/src.next/issues/1138

@fregante

Copy link
Copy Markdown
Member

Thank you! If you’re installing a local build, you can change the manifest locally and double-check. But yeah they still wouldn’t be able to install 24.6.21 and future updates.

However… as part of #7477 I can remove the script from the manifest in the Chrome build and that’ll restore support for Kiwi.

@INSANEMODE

Copy link
Copy Markdown
Contributor Author

Thank you! If you’re installing a local build, you can change the manifest locally and double-check. But yeah they still wouldn’t be able to install 24.6.21 and future updates.

However… as part of #7477 I can remove the script from the manifest in the Chrome build and that’ll restore support for Kiwi.

removing background.script did allow me to install the extension on kiwi.

when tapping the action button, it takes me to github, like the desktop version does. I guess the contextMenus check doesn't work as intended on kiwi, but the background script isn't getting killed, at least.

Maybe it supports the contextMenus permission and chrome.contextMenus isn't undefined, but It doesn't seem like long pressing the button or anything triggers it.

Heading to bed, so i won't be able to narrow down that issue, at the moment.

@fregante

Copy link
Copy Markdown
Member

A couple of things:

The lack of updates also explains why a v121 feature still isn't available (background.script on MV3).

I'm going to keep dropping background.script on MV3 for now, but I won't do any further work for a doubly-unsupported browser (unsupported by them, unsupported by us)

@fregante
fregante merged commit 7e61eb9 into refined-github:main Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug firefox Related to Firefox only mobile

Development

Successfully merging this pull request may close these issues.

2 participants