File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,29 @@ function isHtmlElement(node) {
3636 * @returns {Document | null }
3737 */
3838function getSameOriginIframeDocument ( iframe ) {
39+ // Pre-check conditions that would prevent access without triggering security errors
40+ const src = iframe . src ;
41+ const sandbox = iframe . sandbox ;
42+
43+ // Skip sandboxed iframes unless they explicitly allow scripts
44+ // Avoids: Blocked script execution in 'about:blank' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.
45+ if ( sandbox && sandbox . length > 0 && ! sandbox . contains ( 'allow-scripts' ) ) {
46+ return null ;
47+ }
48+
49+ // Check for cross-origin URLs (but allow about:blank and empty src as they inherit parent origin)
50+ if ( src && src !== 'about:blank' && src !== '' ) {
51+ try {
52+ const iframeUrl = new URL ( src , window . location . href ) ;
53+ if ( iframeUrl . origin !== window . location . origin ) {
54+ return null ;
55+ }
56+ } catch ( e ) {
57+ // Invalid URL, skip
58+ return null ;
59+ }
60+ }
61+
3962 try {
4063 // Try to access the contentDocument - this will throw if cross-origin
4164 const doc = iframe . contentDocument ;
You can’t perform that action at this time.
0 commit comments