diff --git a/src/processing/script/header.ts b/src/processing/script/header.ts index 5c0b2c1e8..0fb76cb1f 100644 --- a/src/processing/script/header.ts +++ b/src/processing/script/header.ts @@ -17,10 +17,15 @@ const STRICT_MODE_PLACEHOLDER = '{strict-placeholder}'; const SW_SCOPE_HEADER_VALUE = '{sw-scope-header-value}'; const WORKER_SETTINGS_PLACEHOLDER = '{worker-settings}'; +// NOTE: we need try/catch if a worker with ES module (fix for https://github.com/DevExpress/testcafe/issues/8251) const IMPORT_WORKER_HAMMERHEAD = ` if (typeof importScripts !== "undefined" && /\\[native code]/g.test(importScripts.toString())) { var ${INSTRUCTION.getWorkerSettings} = function () {return ${WORKER_SETTINGS_PLACEHOLDER}}; - importScripts((location.origin || (location.protocol + "//" + location.host)) + "${SERVICE_ROUTES.workerHammerhead}"); + try { + importScripts((location.origin || (location.protocol + "//" + location.host)) + "${SERVICE_ROUTES.workerHammerhead}"); + } catch (e) { + (async function () { await import((location.origin || (location.protocol + "//" + location.host)) + "${SERVICE_ROUTES.workerHammerhead}"); })(); + } } `; diff --git a/test/server/data/cache/expected-script.js b/test/server/data/cache/expected-script.js index 6690fe2cc..da79fda5a 100644 --- a/test/server/data/cache/expected-script.js +++ b/test/server/data/cache/expected-script.js @@ -1,4 +1,4 @@ -/*hammerhead|script|start*/if (typeof globalThis.window !== 'undefined' && globalThis.window){globalThis.window['hammerhead|process-dom-method'] && globalThis.window['hammerhead|process-dom-method']();if (globalThis.window.__get$ && typeof __get$ === 'undefined')var __get$Loc = globalThis.window.__get$Loc,__set$Loc = globalThis.window.__set$Loc,__set$ = globalThis.window.__set$,__get$ = globalThis.window.__get$,__call$ = globalThis.window.__call$,__get$Eval = globalThis.window.__get$Eval,__proc$Script = globalThis.window.__proc$Script,__proc$Html = globalThis.window.__proc$Html,__get$PostMessage = globalThis.window.__get$PostMessage,__get$ProxyUrl = globalThis.window.__get$ProxyUrl,__rest$Array = globalThis.window.__rest$Array,__rest$Object = globalThis.window.__rest$Object,__arrayFrom$ = globalThis.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,opt=false){return opt&&(o===undefined||o===null)?undefined: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 - diff --git a/test/server/data/page/expected-https.html b/test/server/data/page/expected-https.html index a9cd4b36b..621bb61d1 100644 --- a/test/server/data/page/expected-https.html +++ b/test/server/data/page/expected-https.html @@ -45,7 +45,7 @@ - -