Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define the browsingContext.create command #133

Merged
merged 5 commits into from
Nov 30, 2021

Conversation

foolip
Copy link
Member

@foolip foolip commented Sep 8, 2021

Fixes #116.


Preview | Diff

index.bs Outdated
1. Let |type| be the value of the <code>type</code> field of
|command parameters| if present, or "<code>window</code>" otherwise.

1. TODO: insert step 5 of https://w3c.github.io/webdriver/#new-window verbatim here?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really the main question of this PR, everything I've done is mostly the boilerplate.

https://w3c.github.io/webdriver/#new-window involves the "current browsing context" which we probably want to avoid in BiDi. But without that, presumably we should pass in another browsing context which the new one should be opened after in the tab case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I guess it makes sense to have an optional context, although absent that there's probably a way to talk about using the browsing context which has, or most recently had, OS-level focus as the relevant context in the tab case.

It occurs to me this should be accompanied by a PR to provide a switch-to-context method c.f. https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-bringToFront

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling CDP's Target.createTarget is a lot like a user opening a new unrelated tab, in which case there's no need for an existing/current browsing context.

It almost feels like we should have two commands; One that invokes the window.open steps as WebDriver/HTTP's New Window command does, and one that just creates a new tab/window without an opener relationship as Target.createTarget does.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, so rather than a type argument, two commands for these two operations? https://chromedevtools.github.io/devtools-protocol/tot/Target/#method-createTarget does have a newWindow boolean though, so the precedent seems to be a single command, both in CDP and WebDriver. Am I misunderstanding the suggestion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgraham regarding Page.bringToFront in CDP, do you think the equivalent in BiDi should be browsingContext.bringToFront then?

Perhaps we need to make the concept of a group of browsing contexts (tabs) explicit? Playwright has a notion of BrowserContext which seems to group together their Page objects. The main reason for it seems to be "independent browser sessions" rather than representing a visible window, but there might be something to this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that WebDriver is creating the window with noopener, so it's really a new tab that's not connected to any other tabs. So I think one command that opens a new top level browsing context in either a tab or a window should be fine.

I think BrowserContext in Playwrihgt is trying to solve a different kind of problem; I think it's an abstraction over the idea of multiple containers (in gecko) or private windows (in Blink), which don't share state. It seems like a reasonable idea to surface that concept, but I don't think it's apping 1:1 with OS windows, and is probably a more advanced feature. It's also not a 1:1 mapping with OS windows, which I think is what you're looking for here.

For my money, a browsingContext.bringToFront that would take the context parameter, get the associated top-level-browsing context, and do [something] makes sense. The question is whether [something] should require that it ends up with OS-level focus or just that it's selected context in whatever window it's in without requiring anything at the OS level.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, let's put Playwright's BrowserContext to the side for now.

For the purposes of this PR, my main question is if we want a browsingContext.create command to work without any reference to which window it should open the new browsing context in. The slightly unsatisfying bit is going to be if we add a notion of windows later, there would have to be an implicit window here and we've tried to avoid things like WebDriver's "current top-level browsing context" in BiDi so far.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my proposal from #133 (comment) still makes sense: if you provide a context, the new context should be created as if the user was creating a new context starting at that one (that's hard to specify in detail because to some extent it's an implementation detail, but roughly it would mean a new tab would share an os window with the tab containing that context; I think the text will be necessarily handwavy here).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left this as an inline issue in the spec now, reading:

HTML’s window open steps depend on the "entry global object" and WebDriver’s New Window command depends on the "current browsing context", but we have neither here. What OS window should new tabs be opened in?

@sideshowbarker
Copy link
Contributor

I guess https://labs.w3.org/repo-manager/pr/id/w3c/webdriver-bidi/133 indicates that y’all should have @cwilso add you to the Browser Testing and Tools WG

@foolip
Copy link
Member Author

foolip commented Sep 8, 2021

For my own review later, Target.createTarget seems to be the CDP equivalent command. It's tabs by default, boolean newWindow param to open in a new window.

@foolip
Copy link
Member Author

foolip commented Sep 8, 2021

Looks like CDP has a url parameter, which makes sense, but WebDriver classic doesn't have that and always opens about:blank. We should probably have a URL parameter here.

@jgraham
Copy link
Member

jgraham commented Sep 8, 2021

https://github.com/puppeteer/puppeteer/blob/e94a6b73d3014487b48a018fdcfb5f9874c86bdf/src/common/Browser.ts#L431-L443 seems to be the only use of createTarget in Puppeteer and https://github.com/microsoft/playwright/blob/768a97cfdc4b7425d164a13139ed2d4df358f740/src/server/chromium/crBrowser.ts#L347 in PlayWright. It at least appears that constraining the URL to about:blank and not having width/height parameters for windows is compatible with those uses (I think the problem with non-about:blank URLs is that once that's possible you also want to have the same ability to wait for the page to load as in other navigation commands).

@foolip
Copy link
Member Author

foolip commented Sep 8, 2021

OK, so maybe we should start with about:blank for simplicity. Even so we'll need to decide whether browsingContext.contextCreated, browsingContext.navigationStarted and other navigation/loading-related events are fired. As long as the command response is guaranteed to come before any of the events then it's probably best to simply fire the events.

@foolip
Copy link
Member Author

foolip commented Sep 8, 2021

I guess https://labs.w3.org/repo-manager/pr/id/w3c/webdriver-bidi/133 indicates that y’all should have @cwilso add you to the Browser Testing and Tools WG

Yes, I've seen some email about that :)

@css-meeting-bot
Copy link
Member

The Browser Testing and Tools Working Group just discussed browsing context create command.

The full IRC log of that discussion <AutomatedTester> Topic: browsing context create command
<AutomatedTester> github: https://github.com//pull/133
<AutomatedTester> foolip: THis is a PR that I sent out today
<AutomatedTester> ... it's basically boilerplate and some questions
<jgraham> q+
<AutomatedTester> ... we should merge jgraham's PRs first and then have a look at this PR
<AutomatedTester> ack jgraham
<foolip> q+
<AutomatedTester> jgraham: There is an open question around creating a context and then do we get events? I think the spec already handles this case already
<AutomatedTester> ack foolip
<AutomatedTester> foolip: I think that's right, we will get the events, it's just around the order of the events.
<AutomatedTester> q?

index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
@sadym-chromium
Copy link
Contributor

As asked offline, here is the

raw CDP log when new page with a given URL is open
puppeteer:protocol:SEND ► {"method":"Target.createTarget","params":{"url":"data:text/html,<h2>test</h2>","newWindow":true},"id":2} +8ms
puppeteer:protocol:RECV ◀ {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"05A991FBEA1BF19BCBF846A07FF3A1F1","type":"page","title":"","url":"","attached":false,"canAccessOpener":false,"browserContextId":"8177D676175D58796AAED92BA41EA52C"}}} +6ms
puppeteer:protocol:RECV ◀ {"id":2,"result":{"targetId":"05A991FBEA1BF19BCBF846A07FF3A1F1"}} +2ms
puppeteer:protocol:RECV ◀ {"method":"Target.targetInfoChanged","params":{"targetInfo":{"targetId":"739DC90364B192A143B762598BCEFF61","type":"page","title":"about:blank","url":"about:blank","attached":false,"canAccessOpener":false,"browserContextId":"8177D676175D58796AAED92BA41EA52C"}}} +51ms
puppeteer:protocol:RECV ◀ {"method":"Target.targetInfoChanged","params":{"targetInfo":{"targetId":"05A991FBEA1BF19BCBF846A07FF3A1F1","type":"page","title":"data:text/html,<h2>test</h2>","url":"data:text/html,<h2>test</h2>","attached":false,"canAccessOpener":false,"browserContextId":"8177D676175D58796AAED92BA41EA52C"}}} +1ms
puppeteer:protocol:SEND ► {"method":"Target.attachToTarget","params":{"targetId":"05A991FBEA1BF19BCBF846A07FF3A1F1","flatten":true},"id":3} +56ms
puppeteer:protocol:RECV ◀ {"method":"Target.targetInfoChanged","params":{"targetInfo":{"targetId":"05A991FBEA1BF19BCBF846A07FF3A1F1","type":"page","title":"data:text/html,<h2>test</h2>","url":"data:text/html,<h2>test</h2>","attached":true,"canAccessOpener":false,"browserContextId":"8177D676175D58796AAED92BA41EA52C"}}} +2ms
puppeteer:protocol:RECV ◀ {"method":"Target.attachedToTarget","params":{"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5","targetInfo":{"targetId":"05A991FBEA1BF19BCBF846A07FF3A1F1","type":"page","title":"data:text/html,<h2>test</h2>","url":"data:text/html,<h2>test</h2>","attached":true,"canAccessOpener":false,"browserContextId":"8177D676175D58796AAED92BA41EA52C"},"waitingForDebugger":false}} +0ms
puppeteer:protocol:RECV ◀ {"id":3,"result":{"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"}} +1ms
puppeteer:protocol:SEND ► {"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5","method":"Page.enable","params":{},"id":4} +3ms
puppeteer:protocol:SEND ► {"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5","method":"Page.getFrameTree","params":{},"id":5} +0ms
puppeteer:protocol:SEND ► {"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5","method":"Target.setAutoAttach","params":{"autoAttach":true,"waitForDebuggerOnStart":false,"flatten":true},"id":6} +1ms
puppeteer:protocol:SEND ► {"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5","method":"Performance.enable","params":{},"id":7} +0ms
puppeteer:protocol:SEND ► {"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5","method":"Log.enable","params":{},"id":8} +0ms
puppeteer:protocol:RECV ◀ {"id":4,"result":{},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +36ms
puppeteer:protocol:RECV ◀ {"id":5,"result":{"frameTree":{"frame":{"id":"05A991FBEA1BF19BCBF846A07FF3A1F1","loaderId":"31A2E14BA8313C3EA897A2A94F9FE01D","url":"data:text/html,<h2>test</h2>","domainAndRegistry":"","securityOrigin":"://","mimeType":"text/html","adFrameType":"none","secureContextType":"InsecureScheme","crossOriginIsolatedContextType":"NotIsolated"}}},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +0ms
puppeteer:protocol:RECV ◀ {"id":6,"result":{},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +0ms
puppeteer:protocol:SEND ► {"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5","method":"Page.setLifecycleEventsEnabled","params":{"enabled":true},"id":9} +35ms
puppeteer:protocol:SEND ► {"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5","method":"Runtime.enable","params":{},"id":10} +0ms
puppeteer:protocol:SEND ► {"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5","method":"Network.enable","params":{},"id":11} +0ms
puppeteer:protocol:RECV ◀ {"id":7,"result":{},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +2ms
puppeteer:protocol:RECV ◀ {"id":8,"result":{},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +0ms
puppeteer:protocol:RECV ◀ {"method":"Page.lifecycleEvent","params":{"frameId":"05A991FBEA1BF19BCBF846A07FF3A1F1","loaderId":"31A2E14BA8313C3EA897A2A94F9FE01D","name":"commit","timestamp":1236561.748665},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +0ms
puppeteer:protocol:RECV ◀ {"method":"Page.lifecycleEvent","params":{"frameId":"05A991FBEA1BF19BCBF846A07FF3A1F1","loaderId":"31A2E14BA8313C3EA897A2A94F9FE01D","name":"DOMContentLoaded","timestamp":1236561.800613},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +0ms
puppeteer:protocol:RECV ◀ {"method":"Page.lifecycleEvent","params":{"frameId":"05A991FBEA1BF19BCBF846A07FF3A1F1","loaderId":"31A2E14BA8313C3EA897A2A94F9FE01D","name":"load","timestamp":1236561.800961},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +0ms
puppeteer:protocol:RECV ◀ {"method":"Page.lifecycleEvent","params":{"frameId":"05A991FBEA1BF19BCBF846A07FF3A1F1","loaderId":"31A2E14BA8313C3EA897A2A94F9FE01D","name":"networkAlmostIdle","timestamp":1236561.832845},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +0ms
puppeteer:protocol:RECV ◀ {"method":"Page.lifecycleEvent","params":{"frameId":"05A991FBEA1BF19BCBF846A07FF3A1F1","loaderId":"31A2E14BA8313C3EA897A2A94F9FE01D","name":"networkIdle","timestamp":1236561.832845},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +0ms
puppeteer:protocol:RECV ◀ {"id":9,"result":{},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +0ms
puppeteer:protocol:RECV ◀ {"method":"Runtime.executionContextCreated","params":{"context":{"id":1,"origin":"://","name":"","auxData":{"isDefault":true,"type":"default","frameId":"05A991FBEA1BF19BCBF846A07FF3A1F1"}}},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +4ms
puppeteer:protocol:RECV ◀ {"id":10,"result":{},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +0ms
puppeteer:protocol:RECV ◀ {"id":11,"result":{},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +0ms
puppeteer:protocol:SEND ► {"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5","method":"Page.addScriptToEvaluateOnNewDocument","params":{"source":"//# sourceURL=__puppeteer_evaluation_script__","worldName":"__puppeteer_utility_world__"},"id":12} +6ms
puppeteer:protocol:RECV ◀ {"id":12,"result":{"identifier":"1"},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +1ms
puppeteer:protocol:SEND ► {"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5","method":"Page.createIsolatedWorld","params":{"frameId":"05A991FBEA1BF19BCBF846A07FF3A1F1","grantUniveralAccess":true,"worldName":"__puppeteer_utility_world__"},"id":13} +1ms
puppeteer:protocol:RECV ◀ {"method":"Runtime.executionContextCreated","params":{"context":{"id":2,"origin":"","name":"__puppeteer_utility_world__","auxData":{"isDefault":false,"type":"isolated","frameId":"05A991FBEA1BF19BCBF846A07FF3A1F1"}}},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +3ms
puppeteer:protocol:RECV ◀ {"id":13,"result":{"executionContextId":2},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +1ms
puppeteer:protocol:SEND ► {"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5","method":"Emulation.setDeviceMetricsOverride","params":{"mobile":false,"width":800,"height":600,"deviceScaleFactor":1,"screenOrientation":{"angle":0,"type":"portraitPrimary"}},"id":14} +4ms
puppeteer:protocol:SEND ► {"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5","method":"Emulation.setTouchEmulationEnabled","params":{"enabled":false},"id":15} +0ms
puppeteer:protocol:RECV ◀ {"id":14,"result":{},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +2ms
puppeteer:protocol:RECV ◀ {"id":15,"result":{},"sessionId":"3E4D0B0F6910E3754F2F49B052BE45B5"} +0ms

So the Target.createTarget causes 2 rounds of the events. 1 for an empty page, 2 for the desired page afterwards.

@foolip foolip force-pushed the command-browsingContext-create branch from 78ae090 to 1f454a6 Compare November 24, 2021 17:29
@foolip
Copy link
Member Author

foolip commented Nov 25, 2021

@whimboo do you want to take another look?

index.bs Show resolved Hide resolved
Copy link
Contributor

@whimboo whimboo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I read it right there is still a missing item to get fixed which was inappropriately marked as resoved.

index.bs Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
foolip and others added 2 commits November 30, 2021 13:01
Co-authored-by: Henrik Skupin <mail@hskupin.info>
Copy link
Contributor

@whimboo whimboo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @foolip! This looks fine now. I assume you will merge yourself.

@foolip foolip merged commit f5ce465 into master Nov 30, 2021
@foolip foolip deleted the command-browsingContext-create branch November 30, 2021 14:58
github-actions bot added a commit that referenced this pull request Nov 30, 2021
SHA: f5ce465
Reason: push, by @foolip

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit to sadym-chromium/webdriver-bidi that referenced this pull request Nov 30, 2021
SHA: f5ce465
Reason: push, by @sadym-chromium

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
foolip added a commit that referenced this pull request Nov 30, 2021
foolip added a commit that referenced this pull request May 25, 2022
foolip added a commit that referenced this pull request Oct 5, 2022
This is based on @jgraham's suggestion:
#133 (comment)

Co-authored-by: Julian Descottes <jdescottes@mozilla.com>
Co-authored-by: Maksim Sadym <69349599+sadym-chromium@users.noreply.github.com>
foolip added a commit that referenced this pull request Oct 5, 2022
This is based on @jgraham's suggestion:
#133 (comment)

Co-authored-by: Julian Descottes <jdescottes@mozilla.com>
Co-authored-by: Maksim Sadym <69349599+sadym-chromium@users.noreply.github.com>
foolip added a commit that referenced this pull request Oct 5, 2022
foolip added a commit that referenced this pull request Oct 5, 2022
This is based on @jgraham's suggestion:
#133 (comment)

Co-authored-by: Julian Descottes <jdescottes@mozilla.com>
Co-authored-by: Maksim Sadym <69349599+sadym-chromium@users.noreply.github.com>
whimboo pushed a commit to whimboo/webdriver-bidi that referenced this pull request Feb 3, 2023
This is based on @jgraham's suggestion:
w3c#133 (comment)

Co-authored-by: Julian Descottes <jdescottes@mozilla.com>
Co-authored-by: Maksim Sadym <69349599+sadym-chromium@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Specify creating/opening a browsing context
7 participants