Closed Bug 792458 Opened 7 years ago Closed 7 years ago

Don't allow alert/confirm/prompt in onbeforeunload, onunload and onpagehide.

Categories

(SeaMonkey :: Tabbed Browser, defect)

defect
Not set

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: philip.chee, Assigned: philip.chee)

References

Details

Attachments

(1 file)

From Bug 391834 Comment 0:
> Using onbeforeunload with a loop can render the browser useless.
> 
> As example:
> <body onbeforeunload="for ( var i = 0; i < 999999; i++) { alert('Alert'); }
> return false;">
> 
> If JS is enabled and you tries top close the tab you run into an endless loop 
> with an alert which blocks the complete browser.
> It may be even possible that you can trigger it automatically with a redirect 
> clause.
> It is not a bug just malicious code. IE6 is also affected but i could not get it 
> to work with Opera.
> 
> 
> Reproducible: Always
> 
> Steps to Reproduce:
> 1) Visit the mentioned site with JS on.
> 2) Try to close the tab.
> 
> Actual Results:  
> You get an long chain of alerts and the tab is not closed.
> 
> Expected Results:  
> Allow to ignore the return value from onbeforeunload and allow to close the tab 
> nevertheless.
Attached patch Patch v0.1 WIPSplinter Review
I'm getting some test failures. The first loop works, the second loop that tests an iframe fails with some strange errors e.g.

NS_ERROR_NOT_AVAILABLE: Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIDOMWindow.alert]

INFO TEST-START | Shutdown
Browser Chrome Test Summary
        Passed: 21
        Failed: 5
        Todo: 0

TEST-UNEXPECTED-FAIL | chrome://mochitests/content/browser/suite/browser/test/browser_unloaddialogs.
js | an unexpected uncaught JS exception reported through window.onerror - NS_ERROR_NOT_AVAILABLE: C
omponent returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIDOMWindow.alert] at data:tex
t/html,<script>function%20note(event)%20{%20try%20{%20alert(event.type);%20}%20catch(ex)%20{%20retur
n;%20}%20throw%20'alert%20appeared';%20}</script><body%20onpagehide='note(event)'%20onbeforeunload='
alert(event.type);'%20onunload='note(event)'>Test</body>:1
Stack trace:
    JS frame :: chrome://mochikit/content/tests/SimpleTest/SimpleTest.js :: simpletestOnerror :: lin
e 980
    native frame :: <unknown filename> :: <TOP_LEVEL> :: line 0

TEST-UNEXPECTED-FAIL | chrome://mochitests/content/browser/suite/browser/test/browser_unloaddialogs.
js | an unexpected uncaught JS exception reported through window.onerror - NS_ERROR_NOT_AVAILABLE: C
omponent returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIDOMWindow.alert] at data:tex
t/html,<script>function%20note(event)%20{%20try%20{%20alert(event.type);%20}%20catch(ex)%20{%20retur
n;%20}%20throw%20'alert%20appeared';%20}</script><body%20onpagehide='note(event)'%20onbeforeunload='
alert(event.type);'%20onunload='note(event)'>Frames</body>:1
Stack trace:
    JS frame :: chrome://mochikit/content/tests/SimpleTest/SimpleTest.js :: simpletestOnerror :: lin
e 980
    native frame :: <unknown filename> :: <TOP_LEVEL> :: line 0

TEST-UNEXPECTED-FAIL | chrome://mochitests/content/browser/suite/browser/test/browser_unloaddialogs.
js | pagehides after close - Got 2, expected 3
Stack trace:
    JS frame :: chrome://mochikit/content/browser-test.js :: test_is :: line 471
    JS frame :: chrome://mochitests/content/browser/suite/browser/test/browser_unloaddialogs.js :: s
hown :: line 105
    native frame :: <unknown filename> :: <TOP_LEVEL> :: line 0

TEST-UNEXPECTED-FAIL | chrome://mochitests/content/browser/suite/browser/test/browser_unloaddialogs.
js | beforeunloads after close - Got 6, expected 4
Stack trace:
    JS frame :: chrome://mochikit/content/browser-test.js :: test_is :: line 471
    JS frame :: chrome://mochitests/content/browser/suite/browser/test/browser_unloaddialogs.js :: s
hown :: line 106
    native frame :: <unknown filename> :: <TOP_LEVEL> :: line 0

TEST-UNEXPECTED-FAIL | chrome://mochitests/content/browser/suite/browser/test/browser_unloaddialogs.
js | unloads after close - Got 2, expected 3
Stack trace:
    JS frame :: chrome://mochikit/content/browser-test.js :: test_is :: line 471
    JS frame :: chrome://mochitests/content/browser/suite/browser/test/browser_unloaddialogs.js :: s
hown :: line 107
    native frame :: <unknown filename> :: <TOP_LEVEL> :: line 0

TEST-PASS | chrome://mochitests/content/browser/suite/browser/test/browser_unloaddialogs.js | prompt
s after close
Attachment #662600 - Flags: feedback?(neil)
Depends on: 391834
Sorry, I'm not sure that this will work for us anyway because of the way we undo close tabs.
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → WONTFIX
Attachment #662600 - Flags: feedback?(neil)
You need to log in before you can comment on or make changes to this bug.