Skip to content

Commit

Permalink
feat: do not emit initial navigation events
Browse files Browse the repository at this point in the history
Addressing #2793
  • Loading branch information
sadym-chromium committed Nov 21, 2024
1 parent 51f4706 commit a6c749b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 28 deletions.
59 changes: 35 additions & 24 deletions src/bidiMapper/modules/context/BrowsingContextImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export class BrowsingContextImpl {
* If null, this is a top-level context.
*/
#parentId: BrowsingContext.BrowsingContext | null = null;
/** Flags if the initial navigation to `about:blank` is in progress. */
#initialNavigation = true;

/** Direct children browsing contexts. */
readonly #children = new Set<BrowsingContext.BrowsingContext>();
Expand Down Expand Up @@ -558,36 +560,45 @@ export class BrowsingContextImpl {

switch (params.name) {
case 'DOMContentLoaded':
this.#eventManager.registerEvent(
{
type: 'event',
method: ChromiumBidi.BrowsingContext.EventNames.DomContentLoaded,
params: {
context: this.id,
navigation: this.#navigationId,
timestamp,
url: this.#url,
if (!this.#initialNavigation) {
// Do not emit for the initial navigation.
this.#eventManager.registerEvent(
{
type: 'event',
method:
ChromiumBidi.BrowsingContext.EventNames.DomContentLoaded,
params: {
context: this.id,
navigation: this.#navigationId,
timestamp,
url: this.#url,
},
},
},
this.id,
);
this.id,
);
}
this.#lifecycle.DOMContentLoaded.resolve();
break;

case 'load':
this.#eventManager.registerEvent(
{
type: 'event',
method: ChromiumBidi.BrowsingContext.EventNames.Load,
params: {
context: this.id,
navigation: this.#navigationId,
timestamp,
url: this.#url,
if (!this.#initialNavigation) {
// Do not emit for the initial navigation.
this.#eventManager.registerEvent(
{
type: 'event',
method: ChromiumBidi.BrowsingContext.EventNames.Load,
params: {
context: this.id,
navigation: this.#navigationId,
timestamp,
url: this.#url,
},
},
},
this.id,
);
this.id,
);
}
// The initial navigation is finished.
this.#initialNavigation = false;
this.#lifecycle.load.resolve();
break;
}
Expand Down
5 changes: 1 addition & 4 deletions tests/browsing_context/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ async def test_browsingContext_create_eventContextCreatedEmitted(
@pytest.mark.asyncio
async def test_browsingContext_create_noNavigationEventsEmitted(
websocket, context_id, read_sorted_messages):
pytest.xfail(
"https://github.com/GoogleChromeLabs/chromium-bidi/issues/2793")

await subscribe(websocket, [
"browsingContext.contextCreated", "browsingContext.domContentLoaded",
"browsingContext.load", "browsingContext.navigationStarted"
Expand All @@ -129,7 +126,7 @@ async def test_browsingContext_create_noNavigationEventsEmitted(
'children': None,
'clientWindow': '',
'context': ANY_STR,
'originalOpener': context_id,
'originalOpener': None,
'parent': None,
'url': 'about:blank',
'userContext': 'default',
Expand Down

0 comments on commit a6c749b

Please sign in to comment.