browser(webkit): postpone creation of the first page (#4769)
When we create the first page in the default context in headless mode on mac, it gets NSWindow that is "not visible". Although we call [window setIsVisible:YES], later on window.isVisible still returns NO. We create our offscreen "headless" NSWindow directly from applicationDidFinishLaunching:. Experiments show that delaying this by 100ms makes everything work. As a symptom, we get applicationDidUnhide: notification that does not happen when we create the window immediately. Perhaps, we create the window too early, and there is some essential initialization that happens after applicationDidFinishLaunching:. However, if we call [NSApp activateIgnoringOtherApps:YES] like we do in headful mode, everything works. The only solution that worked so far is creating the first page after a timeout.
This commit is contained in:
parent
9817d1095a
commit
ded2bc2396
|
|
@ -1,2 +1,2 @@
|
||||||
1409
|
1410
|
||||||
Changed: einbinder@chromium.org Wed 23 Dec 2020 08:04:33 AM PST
|
Changed: dgozman@gmail.com Tue Dec 22 18:36:56 PST 2020
|
||||||
|
|
|
||||||
|
|
@ -250,8 +250,18 @@ const NSActivityOptions ActivityOptions =
|
||||||
if (_noStartupWindow)
|
if (_noStartupWindow)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
[self createNewPage:0];
|
// Force creation of the default browser context.
|
||||||
_initialURL = nil;
|
[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
|
- (void)_updateNewWindowKeyEquivalents
|
||||||
|
|
@ -278,7 +288,11 @@ const NSActivityOptions ActivityOptions =
|
||||||
|
|
||||||
- (WKWebView *)createNewPage:(uint64_t)sessionID
|
- (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];
|
WKWebViewConfiguration *configuration = [self sessionConfiguration:sessionID];
|
||||||
if (_headless)
|
if (_headless)
|
||||||
return [self createHeadlessPage:configuration withURL:urlString];
|
return [self createHeadlessPage:configuration withURL:urlString];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue