Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

browser(webkit): postpone creation of the first page (#4769)

Dmitry Gozmanded2bc239690
diff --git a/browser_patches/webkit/BUILD_NUMBER b/browser_patches/webkit/BUILD_NUMBER
index 31df12de77..db0ff38e9a 100644
--- a/browser_patches/webkit/BUILD_NUMBER
+++ b/browser_patches/webkit/BUILD_NUMBER
@@ -1,2 +1,2 @@
-1409
-Changed: [email protected] Wed 23 Dec 2020 08:04:33 AM PST
+1410
+Changed: [email protected] Tue Dec 22 18:36:56 PST 2020
diff --git a/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.m b/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.m
index 3a51a6ea7c..8f20d37177 100644
--- a/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.m
+++ b/browser_patches/webkit/embedder/Playwright/mac/AppDelegate.m
@@ -250,8 +250,18 @@ const NSActivityOptions ActivityOptions =
if (_noStartupWindow)
return;
- [self createNewPage:0];
- _initialURL = nil;
+ // Force creation of the default browser context.
+ [self defaultConfiguration];
+ // Creating the first NSWindow immediately makes it invisible in headless mode,
+ // so we postpone it for 50ms. Experiments show that 10ms is not enough, and 20ms is enough.
+ // We give it 50ms just in case.
+ [NSTimer scheduledTimerWithTimeInterval: 0.05
+ repeats: NO
+ block:(void *)^(NSTimer* timer)
+ {
+ [self createNewPage:0 withURL:_initialURL ? _initialURL : @"about:blank"];
+ _initialURL = nil;
+ }];
}
- (void)_updateNewWindowKeyEquivalents
@@ -278,7 +288,11 @@ const NSActivityOptions ActivityOptions =
- (WKWebView *)createNewPage:(uint64_t)sessionID
{
- NSString* urlString = _initialURL ? _initialURL : @"about:blank";
+ return [self createNewPage:sessionID withURL:@"about:blank"];
+}
+
+- (WKWebView *)createNewPage:(uint64_t)sessionID withURL:(NSString*)urlString
+{
WKWebViewConfiguration *configuration = [self sessionConfiguration:sessionID];
if (_headless)
return [self createHeadlessPage:configuration withURL:urlString];