Skip to content

Commit 0ef966a

Browse files
committed
Build: Improve Playwright detection using newer karma-webkit-launcher
1 parent 8fa7d1f commit 0ef966a

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"karma-ie-launcher": "1.0.0",
5454
"karma-jsdom-launcher": "12.0.0",
5555
"karma-qunit": "4.1.2",
56-
"karma-webkit-launcher": "1.3.1",
56+
"karma-webkit-launcher": "2.1.0",
5757
"load-grunt-tasks": "5.1.0",
5858
"native-promise-only": "0.8.1",
5959
"playwright-webkit": "1.29.2",

test/unit/selector.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
QUnit.module( "selector", {
22
beforeEach: function() {
33

4-
// Playwright WebKit on macOS doesn't expose `Safari` in its user agent string.
5-
// However, this particular version of WebKit is only present in modern
6-
// WebKit UAs (Safari 13+) as Chromium is locked to an older version.
4+
// Playwright WebKit on macOS doesn't expose `Safari` in its user agent
5+
// string; use the "AppleWebKit" token. This token is also present
6+
// in the Chromium UA, but it is locked to an older version there.
7+
// Modern WebKit (Safari 13+) locks it to `605.1.15`.
78
this.safari = /\bapplewebkit\/605\.1\.15\b/i.test( navigator.userAgent );
89
},
910
afterEach: moduleTeardown

test/unit/support.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,17 @@ testIframe(
107107
expected = expectedMap.firefox;
108108
} else if ( /(?:iphone|ipad);.*(?:iphone)? os \d+_/i.test( userAgent ) ) {
109109
expected = expectedMap.ios;
110-
} else if (
111-
112-
// Playwright WebKit on macOS doesn't expose `Safari` in its user agent string.
113-
// However, this particular version of WebKit is only present in modern
114-
// WebKit UAs (Safari 13+) as Chromium is locked to an older version.
115-
( /\bapplewebkit\/605\.1\.15\b/i.test( userAgent ) &&
116-
!/\bsafari\//i.test( userAgent ) ) ||
117-
118-
// The Linux version of Playwright WebKit does include the `Safari` token,
119-
// though. Since there's no WebKit-based real browser that we officially
120-
// support outside of macOS and GitHub Actions run on Linux, use it to
121-
// detect Playwright WebKit.
122-
/\blinux [^)]+\) applewebkit\/605\.1\.15\b/i.test( userAgent ) ) {
110+
} else if ( typeof URLSearchParams !== "undefined" &&
111+
112+
// `karma-webkit-launcher` adds `test_browser=Playwright` to the query string.
113+
// The normal way of using user agent to detect the browser won't help
114+
// as on macOS Playwright doesn't specify the `Safari` token but on Linux
115+
// it does.
116+
// See https://github.com/google/karma-webkit-launcher#detected-if-safari-or-playwright-is-used
117+
new URLSearchParams( document.referrer || window.location.search ).get(
118+
"test_browser"
119+
) === "Playwright"
120+
) {
123121
expected = expectedMap.webkit;
124122
} else if ( /\b\d+(\.\d+)+ safari/i.test( userAgent ) ) {
125123
expected = expectedMap.safari;

0 commit comments

Comments
 (0)