From 97b6f33cc28a46efc34f9fb3215612e3cc36d665 Mon Sep 17 00:00:00 2001 From: Mert Akinc <7282195+m-akinc@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:45:23 -0500 Subject: [PATCH] Add test, update rexex pattern and constant name --- spec/core/ClearStackSpec.js | 13 +++++++++++++ src/core/ClearStack.js | 8 +++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/spec/core/ClearStackSpec.js b/spec/core/ClearStackSpec.js index 626969f5..3f9b47b1 100644 --- a/spec/core/ClearStackSpec.js +++ b/spec/core/ClearStackSpec.js @@ -22,6 +22,19 @@ describe('ClearStack', function() { }); }); + describe('in WebKit (Playwright\'s build for Windows)', function() { + usesQueueMicrotaskWithSetTimeout(function() { + return { + navigator: { + userAgent: + 'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/605.1.15 (KHTML, like Gecko)' + }, + // queueMicrotask should be used even though MessageChannel is present + MessageChannel: fakeMessageChannel + }; + }); + }); + describe('in browsers other than Safari', function() { usesMessageChannel(function() { return { diff --git a/src/core/ClearStack.js b/src/core/ClearStack.js index 23b6da78..b5711c08 100644 --- a/src/core/ClearStack.js +++ b/src/core/ClearStack.js @@ -68,9 +68,11 @@ getJasmineRequireObj().clearStack = function(j$) { global.process.versions && typeof global.process.versions.node === 'string'; - const SAFARI = + // Windows builds of WebKit have a fairly generic user agent string when no application name is provided. + // See: https://github.com/WebKit/WebKit/blob/d898a3cffd9c992980016cb1fbdba272cb0c992d/Source/WebCore/platform/win/UserAgentWin.cpp#L37 + const SAFARI_OR_WIN_WEBKIT = global.navigator && - /(^((?!chrome|android).)*safari)|(^((?!chrome|android|firefox).)+$)/i.test( + /(^((?!chrome|android).)*safari)|(Win64; x64\) AppleWebKit\/[0-9.]+ \(KHTML, like Gecko\)$)/i.test( global.navigator.userAgent ); @@ -79,7 +81,7 @@ getJasmineRequireObj().clearStack = function(j$) { // so we avoid the overhead. return nodeQueueMicrotaskImpl(global); } else if ( - SAFARI || + SAFARI_OR_WIN_WEBKIT || j$.util.isUndefined(global.MessageChannel) /* tests */ ) { // queueMicrotask is dramatically faster than MessageChannel in Safari,