before unload, prompt user if they really want to close?

41 views
Skip to first unread message

Nathan Pierce

unread,
Feb 4, 2023, 9:58:54 AM2/4/23
to Chromium Extensions
I've tried many versions of triggering a confirmation to the user if they close the extension window and none seem to work. Is beforeunload still allowed, or has it been disabled to prevent abuse?

Nathan Pierce

unread,
Feb 4, 2023, 10:18:23 AM2/4/23
to Chromium Extensions, Nathan Pierce
Per https://chromestatus.com/feature/5082396709879808,

> The beforeunload dialog will only be shown if the frame attempting to display it has received a user gesture or user interaction (or if any embedded frame has received such a gesture). (There will be no change to the dispatch of the beforeunload event, just a change to whether the dialog is shown.)

hrg...@gmail.com

unread,
Feb 4, 2023, 11:02:33 AM2/4/23
to Chromium Extensions, nors...@gmail.com
This works for me:

window.addEventListener('beforeunload', evt =>{ evt.returnValue = true })

Nathan Pierce

unread,
Feb 4, 2023, 11:04:01 AM2/4/23
to Chromium Extensions, hrg...@gmail.com, Nathan Pierce
Yep, that's what I have. I found the answer: I wasn't interacting with the extension before trying to close it, so the beforeunload never triggered.
Reply all
Reply to author
Forward
0 new messages