File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < script src ="/resources/testharness.js "> </ script >
3+ < script src ="/resources/testharnessreport.js "> </ script >
4+ < script src ="/common/rendering-utils.js "> </ script >
5+ < script src ="./support/csp-violations.js "> </ script >
6+ < script src ="./support/navigation-support.js "> </ script >
7+ < script >
8+ promise_test ( async _ => {
9+ await new Promise ( resolve => window . addEventListener ( "load" , resolve ) ) ;
10+ const result = await setLocationToJavaScriptURL ( "throw" /* defaultpolicy */ ) ;
11+ // This is odd but CSP pre-navigation checks on report-only directives cannot block navigation.
12+ assert_true ( result . javaScriptExecuted , "JavaScript should have been executed" ) ;
13+ assert_equals ( result . violations . length , 1 ) ;
14+ const violation = result . violations [ 0 ] ;
15+ assert_equals ( violation . violatedDirective , "require-trusted-types-for" ) ;
16+ assert_equals ( violation . disposition , "report" ) ;
17+ assert_equals ( violation . sample , `Location href|${ clipSampleIfNeeded ( kJavaScriptURLCode ) } ` ) ;
18+ assert_equals ( result . exception , null , "No exception" ) ;
19+ } , "Setting window.location to a javascript: URL with a default policy that throws should report a CSP violation without rethrowing the exception." ) ;
20+ </ script >
Original file line number Diff line number Diff line change 1+
2+ Content-Security-Policy: connect-src 'none';
3+ Content-Security-Policy-Report-Only: require-trusted-types-for 'script'
Original file line number Diff line number Diff line change @@ -60,6 +60,8 @@ async function setLocationToJavaScriptURL(defaultpolicy) {
6060 // pre-navigation check CSP violation.
6161 if ( window . requestIdleCallback ) {
6262 await new Promise ( resolve => requestIdleCallback ( resolve ) ) ;
63+ } else {
64+ await new Promise ( resolve => requestAnimationFrame ( _ => requestAnimationFrame ( resolve ) ) ) ;
6365 }
6466 } ) ;
6567
@@ -188,6 +190,11 @@ function navigateToJavascriptURL(reportOnly) {
188190 requestIdleCallback ( resolve ) ;
189191 window . addEventListener ( "beforeunload" , resolve ) ;
190192 } ) ;
193+ } else {
194+ await new Promise ( resolve => requestAnimationFrame ( ( ) => {
195+ requestAnimationFrame ( resolve ) ;
196+ window . addEventListener ( "beforeunload" , resolve ) ;
197+ } ) ) ;
191198 }
192199 } ) ;
193200 if ( exception ) {
You can’t perform that action at this time.
0 commit comments