Hello we have a question about PWA and window.close events,
Before asking the question we will give some background information why we are asking this question in the first place.
We are trying to rebuild our XUL appllication to a HTML5 one with webcomponents and PWA. In this XUL Application there are allot of pop-ups with there own child windows,the user shouldn't be able to close a parent window while still having edited data inside a child window. This problem is solved when using the beforeunload event on the window object. One small problem you can't really customize this events behavior the user just gets the default message of data loss.The custom message behavior isn't available anymore because the behavior is obsolete since chrome 51.
So far the background of the problem we are trying to solve.
The question,
isn't there any setting inside the PWA manifest.json so you could ask user permission settings to be changed when the PWA is installed and run for the first time. And when this happens the user will be asked to give permission for the window.close event to be cancel-able. When doing this the user confirms to custom or none beforeunload alert pop-ups. This behavior will only be activated if the PWA is installed to the desktop of the user.
Hopefully this is or will be a option.
No, there is no permissions definition in webapp manifest.
(there is something similar for chrome extensions though)
By definition a PWA should behave as a native application, so if you are rewriting software to be a PWA you should re-model your application logic so that it stores the last state of the application on localStorage/indexedDB or similar and reads it upon starting and this would enforce the user to stay on the state you need it. No one should enforce the user to stay with the application open when they don't want.
Related
The Chrome dev team apparently just rolled out a new "feature" called SuppressDifferentOriginSubframeJSDialogs, which makes it so alert+confirm boxes from an iFrame on a different domain than the parent does not show up, by default: https://www.chromestatus.com/feature/5148698084376576
This means if you have an embedded form, and you relied upon the standard JavaScript alert to inform the user of errors (or a confirm to ensure they want to make a change), it now does nothing, completely destroying the UX.
Obviously we can overwrite the built-in alert and confirms with custom ones, but moving away from what is built into the browser now introduces re-designs for every UI (mobile, tablet, laptop, desktop, etc.) instead of just relying upon proven, built-in technology.
Is there a way to change this cross-domain setting, or to whitelist specific domains to override this feature? We do have access to the parent site with an external JS include file (obviously, otherwise this would be a wide-open back door).
To Disable SuppressDifferentOriginSubframeJSDialogs , which block js Dialog box pop up
If you are single users ( Windows ) :
Right click on desktop and create a shortcut
Windows will pop up a screen and ask you "type the location of the item:"....now paste those value into the textbox
"C:\Program Files\Google\Chrome\Application\chrome.exe" --disable-features=SuppressDifferentOriginSubframeJSDialogs
Click "next" then "finish" button to create the shortcut
Now you shall see a chrome shortcut created in your desktop .Close all active Chrome instance ( if exists ) then launch the shortcut and you will found Js pop up wont block anymore.
Tips :
If you want push this fix to all your cooperate domain users , you may consider use Domain group policy to update Chrome shortcut value or use custom domain logon script logic to do so
I found a setting in the latest Chrome GPO template that creates a reg entry that will deal with this and the same reg entry placed in the Edge location also resolves the error there. (at least it worked for the problem that came up for us yesterday FWIW)
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Edge]
"SuppressDifferentOriginSubframeDialogs"=dword:00000000
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome]
"SuppressDifferentOriginSubframeDialogs"=dword:00000000
The latest Edge GPO templates do not have the setting yet, but I imagine it's only a matter of time.
Today I tried it again with Google Chrome Version 92.0.4515.131 and it suddenly worked again. Can anyone confirm this?
Add for Mac users.
If you use mac OS:
Quit all running instances of Chrome.
Run the terminal application.
In the terminal, run the command:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --disable-features="SuppressDifferentOriginSubframeJSDialogs"
You can see more details here :
https://trailblazer.salesforce.com/issues_view?title=salesforce-functionality-impacted-in-[%E2%80%A6]oss-origin-iframe-javascript-dialogs&Id=a1p4V000002BRMX
Individuals will quickly want to mark this question as a duplicate, but, please read this question first.
I have a PWA. A user can successfully install this app from my website. However, they may visit the website again from their browser. If they do this, Chrome shows a "choose app" icon in place of the "install" icon in the address bar. My question is, can I programmatically detect if the app has been installed?
The common recommendation is to use window.matchMedia('(display-mode: standalone)').matches. However, in the scenario above, the display-mode will be "tab" (i.e. not 'standalone'). I would like to detect if the app is installed in my page and "open" the app just like Chrome does. Is this possible?
I have an Add to Homescreen library that tries to abstract away all the different browser/platform differences.
It now has a hook/callback in the library that will execute your code if the application can be installed. So, it should not fire that callback if the application is installed.
It also persist an add to homescreen state in localStorage because there is not a real way to really know if the app has been installed or not. The values persisted let A2HS know if the app has been installed from the library. In Edge and Chrome it will know because the beforeInstallPrompt event will not trigger.
https://love2dev.com/pwa/add-to-homescreen-library/
GitHub Repo - https://github.com/docluv/add-to-homescreen
Within my app I have a flag saying if data needs saving or not m_IsSaved.
If the user closes the app when m_IsSaved is false I need to give them a warning message and give them the option to return to the app without closing.
Ie, if they click YES the app closes normally. If they click NO then the app stays open and does not close. (This will then give them the option to save their data. The save function is already written and works fine.)
How is this done in javascript?
According to your description, it seems you want to prevent your UWP app from closing when m_IsSaved is false. However, this is not possible. For UWP apps, we can't prevent the app from suspending or closing.
Refer App close:
There is not an event to indicate that the user closed the app. When an app is closed by the user, it is first suspended to give you an opportunity to save its state.
So you can always save the data with Application.Suspending event (for WinJS app, it would be WinJS.Application.oncheckpoint event). I think there is no need to prevent users from closing your app.
For more info, please see Windows 10 universal Windows platform (UWP) app lifecycle.
In the top of my website pages, I like to recommend to view my site with chrome and suggest to change browser add a button that when the user click it, one of the 2 options will happen:
If the chrome is already installed -> the page will be opened on the chrome (if the user's default browser isn't chrome).
If the chrome isn't installed -> popup message that says: "chrome hasn't been installed yet. For free download:link"
I assume that these two functions are already exist but I don't even know where to start searching....
Any help will be appreciated!!!
There is no way to detect what applications are installed on a computer using client side JavaScript (or any information that it sent to the server).
A webpage cannot trigger the loading on an arbitrary application on the client.
So no, neither of this functions exist and they cannot be written.
I am working on a client server application,in which we open client on our pc by URL:http:\[ip of server]:[port no].
My application start by using the URL mentioned in IE, and one pop-up comes in which we perform every action of the apllication and original window we can close as they are only for starting. One of my customer is using IE8 and he is facing a problem in which after clicking on save to bookmark the pop-up is not coming and hence not able to save. In IE7 pop-up as an another window is coming and giving the option to save.
What is blocking the pop-up? Thanks in Advance...
For popups the same goes as for spam email - as the popup developers get smarter, so do the popup blocker developers. As such it makes sense that newer browser versions are stricter in the rules they evaluate to determine when a popup needs to be blocked.
All modern browsers follow the same rules, that all boil down to "popups are only allowed if the user directly initiated them". This means that they guard execution paths, and every call to window.open is caught by the popup blocker unless it can be directly traced to a user action. And as popup developers invented more inventive ways to make a browser think the user initiated it, popup blockers got more inventive in detecting them.
A quite plausible explanation is also that you are developing on a LAN, where IE applies lower security settings by default, allowing more user popups automatically. We cannot see that from your post though.