Version: 56
OS: Android
What steps will reproduce the problem?
(1) Set up a PWA site with a service worker, manifest, etc.
(2) Use attached index.js.
(3) Turn on chrome://flags#bypass-app-banner-engagement-checks
(4) Open inspector.
(5) Visit site.
What is the expected output?
After 1 second, add to home screen banner is shown.
What do you see instead?
After 1 second, console error:
prompt() failed: InvalidStateError: The prompt() method may only be called once, following preventDefault().
The code in index.js is:
window.addEventListener('beforeinstallprompt', e => {
e.preventDefault();
window.setTimeout(() => {
e.prompt()
.then(() => console.log('prompt() succeeded'))
.catch(e => console.error('prompt() failed: ' + e));
}, 1000);
e.userChoice.then(c => console.log('userChoice resolved: ' + c));
});
The line "e.userChoice.then(...)" is causing this. Comment out that line, and you get the expected behaviour. Note that this happens regardless of whether you call then() on userChoice (just accessing userChoice is sufficient).
Accessing the userChoice attribute before calling prompt() causes prompt() to fail. A work-around is to only access userChoice after prompt() resolves, but this shouldn't be the case.
|
Deleted:
index.js
432 bytes
|
Comment 1 by dominickn@chromium.org
, Oct 14 2016Owner: dominickn@chromium.org
Status: Started (was: Available)