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

Changing the default links target option #457

Open
Jaifroid opened this issue Jan 24, 2024 · 4 comments
Open

Changing the default links target option #457

Jaifroid opened this issue Jan 24, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@Jaifroid
Copy link

Problem Description

In my PWA, I have code that opens external links and PDFs as new tabs or new windows with window.open(url, '_blank'). This works in Chromium PWAs, and in in-browser Firefox, but it appears to be blocked in this standalone PWA mode. This is a problem, given that our CSP forbids opening external links or PDFs inside the iframe which contains the contents of our app, for security reasons. All such links must be opened in a new window or tab. But instead, in this version, the new document attempts to open as _top.

Proposed Solution

Allow opening new windows or tabs from window.open(url, target) and also (I did not test this) from anchors with target="_blank".

Additional Information

The current behaviour appears to treat the _blank target as if it were the _top target, which is problematic because any document opened with _blank (or at least with window.open(url, '_blank')) overwrites the PWA's HTML. It's sometimes possible to restore it with back arrow, but it often causes the PWA to reload, rather than returning the user to the last state of the PWA's UI.

@Jaifroid Jaifroid added the enhancement New feature or request label Jan 24, 2024
@Jaifroid
Copy link
Author

On further testing, I see it is possible to open a new window with right-click. This works well because the original PWA is not overwritten. However, doing so in code, as mentioned above, doesn't appear to work. It's good that it is technically possible to open a new window, i.e. that standalone mode does allow it, albeit manually.

@filips123
Copy link
Owner

This can be changed by the user in the app browser settings with the "When opening a link that should normally open in a new window or tab" option. If it's set to "Force links into the current tab" (which is the default), then all links will be opened in the current tab. If it's set to "Force links into a new window", then they will be opened in a new window.

And to be honest, I'm not completely sure why I've chosen the current tab as a default. I think there are/were some problems with built-in Firefox links (from menus and such) if opening in new windows is selected.

@Jaifroid
Copy link
Author

Ah, OK, thanks for the info and the super-quick response.

IMHO, I think the default setting should be "Do not change link behaviour" unless it's really producing problems for the app. On a quick test, I didn't notice any issues. As this is the default behaviour of all browsers, it would seem more intuitive for any "force" setting to be a deliberate user choice rather than a default.

Setting it to "Do not change link behaviour" does what I want, though as it is I'll have to tell users of my PWA to change the default, for the reasons mentioned above. Should I close this issue and (if you think it's a good idea) open a new one to explore changing the default?

@filips123
Copy link
Owner

I think that specifically "Do not change link behaviour" causes the most problems.

For example, I think that one of the problems is that when this option is enabled, some links will be opened in new tabs and some in new windows. And when you click on a link that opens something in a new tab, the old tab will remain loaded. The problem is that because tabs are hidden in PWAs, you wouldn't know the old tab is still loaded. So, if you then opened a few more such links, you would build a set of hidden tabs that could be just taking resources without a way to access them (well, you could switch tabs with Ctrl+Tab but that isn't something that users would normally do in PWA).

So, if we were to change the default, I think that "Force links into a new window" is a better option. If that option is enabled, it also handles a few more ways to open links that are normally not handled to make it more consistent and reliable. However, I still need to check if it causes any problems and if I need to fix anything. And, well, to check what exactly that function does, in case anything has changed in Firefox internally since I originally wrote it, or I forgot anything. Maybe I'll also split the preference into multiple ones, but I'm not sure yet.

though as it is I'll have to tell users of my PWA to change the default

I think that for now, this is probably what you should do... Because I don't have much time currently and there are also a few other things that I would like to do before doing this.

Should I close this issue and (if you think it's a good idea) open a new one to explore changing the default?

I'll just rename this one.

@filips123 filips123 changed the title Allow opening a new "browser" window from within the PWA Changing the default links target option Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: To Do
Development

No branches or pull requests

2 participants