From 535c7c18a37d54f3452ffbdfe063ce8b2dab9da5 Mon Sep 17 00:00:00 2001 From: Adil Rakhaliyev <67043367+Bayheck@users.noreply.github.com> Date: Mon, 4 Nov 2024 12:40:52 +0500 Subject: [PATCH] fix: issue fixed by replacing window with globalThis (#3026) * fix: issue fixed by replacing window with globalThis * tests fixed * tests fixed * client tests fixed * fix client tests * fix client tests * fix: client test fixed * fix: server tests fixed --------- Co-authored-by: Bayheck --- gulp/saucelabs-settings.js | 2 +- src/processing/script/header.ts | 34 +++++++++--------- .../node/html-collection-wrapper-test.js | 2 +- test/server/data/cache/expected-script.js | 4 +-- .../data/html-import-page/expected.html | 34 +++++++++--------- test/server/data/page/expected-https.html | 35 +++++++++++++------ test/server/data/page/expected.html | 35 +++++++++++++------ test/server/data/script/expected.js | 2 +- .../service-worker/expected-with-header.js | 2 +- test/server/data/service-worker/expected.js | 2 +- 10 files changed, 92 insertions(+), 60 deletions(-) diff --git a/gulp/saucelabs-settings.js b/gulp/saucelabs-settings.js index 73e94b305..55324a175 100644 --- a/gulp/saucelabs-settings.js +++ b/gulp/saucelabs-settings.js @@ -24,7 +24,7 @@ const CLIENT_TESTS_BROWSERS = [ { browserName: 'Safari', deviceName: 'iPhone 7 Plus Simulator', - platformVersion: '11.3', + platformVersion: '12.2', platformName: 'iOS', }, { diff --git a/src/processing/script/header.ts b/src/processing/script/header.ts index 7f25e5c77..c01e6e442 100644 --- a/src/processing/script/header.ts +++ b/src/processing/script/header.ts @@ -24,7 +24,7 @@ if (typeof importScripts !== "undefined" && /\\[native code]/g.test(importScript } `; -const PROCESS_DOM_METHOD = `window['${INTERNAL_PROPS.processDomMethodName}'] && window['${INTERNAL_PROPS.processDomMethodName}']();`; +const PROCESS_DOM_METHOD = `globalThis.window['${INTERNAL_PROPS.processDomMethodName}'] && globalThis.window['${INTERNAL_PROPS.processDomMethodName}']();`; function trim (val: string): string { return val.replace(/\n(?!$)\s*/g, ''); @@ -34,7 +34,7 @@ const NATIVE_AUTOMATION_HEADER = trim(` ${SCRIPT_PROCESSING_START_COMMENT} ${STRICT_MODE_PLACEHOLDER} - if (typeof window !== 'undefined' && window) { + if (typeof globalThis.window !== 'undefined' && globalThis.window) { ${PROCESS_DOM_METHOD} } @@ -46,23 +46,23 @@ const HEADER = trim(` ${STRICT_MODE_PLACEHOLDER} ${SW_SCOPE_HEADER_VALUE} - if (typeof window !== 'undefined' && window){ + if (typeof globalThis.window !== 'undefined' && globalThis.window){ ${PROCESS_DOM_METHOD} - if (window.${INSTRUCTION.getProperty} && typeof ${INSTRUCTION.getProperty} === 'undefined') - var ${INSTRUCTION.getLocation} = window.${INSTRUCTION.getLocation}, - ${INSTRUCTION.setLocation} = window.${INSTRUCTION.setLocation}, - ${INSTRUCTION.setProperty} = window.${INSTRUCTION.setProperty}, - ${INSTRUCTION.getProperty} = window.${INSTRUCTION.getProperty}, - ${INSTRUCTION.callMethod} = window.${INSTRUCTION.callMethod}, - ${INSTRUCTION.getEval} = window.${INSTRUCTION.getEval}, - ${INSTRUCTION.processScript} = window.${INSTRUCTION.processScript}, - ${INSTRUCTION.processHtml} = window.${INSTRUCTION.processHtml}, - ${INSTRUCTION.getPostMessage} = window.${INSTRUCTION.getPostMessage}, - ${INSTRUCTION.getProxyUrl} = window.${INSTRUCTION.getProxyUrl}, - ${INSTRUCTION.restArray} = window.${INSTRUCTION.restArray}, - ${INSTRUCTION.restObject} = window.${INSTRUCTION.restObject}, - ${INSTRUCTION.arrayFrom} = window.${INSTRUCTION.arrayFrom}; + if (globalThis.window.${INSTRUCTION.getProperty} && typeof ${INSTRUCTION.getProperty} === 'undefined') + var ${INSTRUCTION.getLocation} = globalThis.window.${INSTRUCTION.getLocation}, + ${INSTRUCTION.setLocation} = globalThis.window.${INSTRUCTION.setLocation}, + ${INSTRUCTION.setProperty} = globalThis.window.${INSTRUCTION.setProperty}, + ${INSTRUCTION.getProperty} = globalThis.window.${INSTRUCTION.getProperty}, + ${INSTRUCTION.callMethod} = globalThis.window.${INSTRUCTION.callMethod}, + ${INSTRUCTION.getEval} = globalThis.window.${INSTRUCTION.getEval}, + ${INSTRUCTION.processScript} = globalThis.window.${INSTRUCTION.processScript}, + ${INSTRUCTION.processHtml} = globalThis.window.${INSTRUCTION.processHtml}, + ${INSTRUCTION.getPostMessage} = globalThis.window.${INSTRUCTION.getPostMessage}, + ${INSTRUCTION.getProxyUrl} = globalThis.window.${INSTRUCTION.getProxyUrl}, + ${INSTRUCTION.restArray} = globalThis.window.${INSTRUCTION.restArray}, + ${INSTRUCTION.restObject} = globalThis.window.${INSTRUCTION.restObject}, + ${INSTRUCTION.arrayFrom} = globalThis.window.${INSTRUCTION.arrayFrom}; } else { if (typeof ${INSTRUCTION.getProperty} === 'undefined') var ${INSTRUCTION.getLocation} = function(l){return l}, diff --git a/test/client/fixtures/sandbox/node/html-collection-wrapper-test.js b/test/client/fixtures/sandbox/node/html-collection-wrapper-test.js index eee802768..a180a75e5 100644 --- a/test/client/fixtures/sandbox/node/html-collection-wrapper-test.js +++ b/test/client/fixtures/sandbox/node/html-collection-wrapper-test.js @@ -100,7 +100,7 @@ module('getElementsByTagName', function () { var elementsCount = 0; var expectedProps = ['item', 'namedItem', 'length']; - if (browserUtils.isMacPlatform && browserUtils.isSafari) + if ((browserUtils.isMacPlatform || browserUtils.isIOS) && browserUtils.isSafari) expectedProps.push('constructor'); for (var idx in collection) { diff --git a/test/server/data/cache/expected-script.js b/test/server/data/cache/expected-script.js index 39ccfb687..b4fae732b 100644 --- a/test/server/data/cache/expected-script.js +++ b/test/server/data/cache/expected-script.js @@ -1,7 +1,7 @@ -/*hammerhead|script|start*/if (typeof window !== 'undefined' && window){window['hammerhead|process-dom-method'] && window['hammerhead|process-dom-method']();if (window.__get$ && typeof __get$ === 'undefined')var __get$Loc = window.__get$Loc,__set$Loc = window.__set$Loc,__set$ = window.__set$,__get$ = window.__get$,__call$ = window.__call$,__get$Eval = window.__get$Eval,__proc$Script = window.__proc$Script,__proc$Html = window.__proc$Html,__get$PostMessage = window.__get$PostMessage,__get$ProxyUrl = window.__get$ProxyUrl,__rest$Array = window.__rest$Array,__rest$Object = window.__rest$Object,__arrayFrom$ = window.__arrayFrom$;} else {if (typeof __get$ === 'undefined')var __get$Loc = function(l){return l},__set$Loc = function(l,v){return l = v},__set$ = function(o,p,v){return o[p] = v},__get$ = function(o,p){return o[p]},__call$ = function(o,p,a){return o[p].apply(o,a)},__get$Eval = function(e){return e},__proc$Script = function(s){return s},__proc$Html = function(h){return h},__get$PostMessage = function(w,p){return arguments.length===1?w.postMessage:p},__get$ProxyUrl = function(u,d){return u},__rest$Array = function(a,i){return Array.prototype.slice.call(a, i)},__rest$Object = function(o,p){var k=Object.keys(o),n={};for(var i=0;i + + { + a : __get$(window,"location") + } + +/*hammerhead|script|end*/ + +/*hammerhead|script|end*/ @@ -43,4 +43,6 @@
- + + + \ No newline at end of file diff --git a/test/server/data/page/expected-https.html b/test/server/data/page/expected-https.html index c58d97f03..547277202 100644 --- a/test/server/data/page/expected-https.html +++ b/test/server/data/page/expected-https.html @@ -38,29 +38,42 @@ background-image: url(https://127.0.0.1:1836/sessionId*12345/http://some.url); background: repeat-y url(https://127.0.0.1:1836/sessionId*12345/http://base.url/some/other/url) #fc0; } + /*hammerhead|stylesheet|end*/ - + - @@ -71,7 +84,7 @@ - + @@ -99,7 +112,7 @@ - + @@ -125,4 +138,6 @@ - + + + \ No newline at end of file diff --git a/test/server/data/page/expected.html b/test/server/data/page/expected.html index 512a8fd61..90a14126f 100644 --- a/test/server/data/page/expected.html +++ b/test/server/data/page/expected.html @@ -38,29 +38,42 @@ background-image: url(http://127.0.0.1:1836/sessionId*12345/http://some.url); background: repeat-y url(http://127.0.0.1:1836/sessionId*12345/http://base.url/some/other/url) #fc0; } + /*hammerhead|stylesheet|end*/ - + - @@ -71,7 +84,7 @@ - + @@ -99,7 +112,7 @@ - + @@ -125,4 +138,6 @@ - + + + \ No newline at end of file diff --git a/test/server/data/script/expected.js b/test/server/data/script/expected.js index ba1036ed7..e39380e95 100644 --- a/test/server/data/script/expected.js +++ b/test/server/data/script/expected.js @@ -1,4 +1,4 @@ -/*hammerhead|script|start*/if (typeof window !== 'undefined' && window){window['hammerhead|process-dom-method'] && window['hammerhead|process-dom-method']();if (window.__get$ && typeof __get$ === 'undefined')var __get$Loc = window.__get$Loc,__set$Loc = window.__set$Loc,__set$ = window.__set$,__get$ = window.__get$,__call$ = window.__call$,__get$Eval = window.__get$Eval,__proc$Script = window.__proc$Script,__proc$Html = window.__proc$Html,__get$PostMessage = window.__get$PostMessage,__get$ProxyUrl = window.__get$ProxyUrl,__rest$Array = window.__rest$Array,__rest$Object = window.__rest$Object,__arrayFrom$ = window.__arrayFrom$;} else {if (typeof __get$ === 'undefined')var __get$Loc = function(l){return l},__set$Loc = function(l,v){return l = v},__set$ = function(o,p,v){return o[p] = v},__get$ = function(o,p){return o[p]},__call$ = function(o,p,a){return o[p].apply(o,a)},__get$Eval = function(e){return e},__proc$Script = function(s){return s},__proc$Html = function(h){return h},__get$PostMessage = function(w,p){return arguments.length===1?w.postMessage:p},__get$ProxyUrl = function(u,d){return u},__rest$Array = function(a,i){return Array.prototype.slice.call(a, i)},__rest$Object = function(o,p){var k=Object.keys(o),n={};for(var i=0;i