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

api(chromium): remove Target from public API #1163

Merged
merged 4 commits into from
Mar 2, 2020

Conversation

yury-s
Copy link
Member

@yury-s yury-s commented Feb 28, 2020

  • Removed Events.CRBrowserContext.Target{Created,Destroyed,Changed} in favor of "pageevent" on BrowserContext
  • New pages can are now reported by firing 'pageevent' on the BrowserContext
  • Background pages can be discovered via ChromiumBrowserContext.backgroundPages() and Events.CRBrowserContext.BackgroundPage event on the context.
  • Service workers can be discovered by listening to Events.CRBrowserContext.ServiceWorker event.
  • New CDP sessions can now be created
    • for a Page: ChromiumBrowserContext.createSession(page)
    • for a Browser: ChromiumBrowser.createBrowserSession()

References: #1101

@jperl
Copy link
Contributor

jperl commented Feb 28, 2020

"New pages can be reported by firing 'pageevent' on the BrowserContext" This makes so many things easier. Thank you! 🙏

- <[PageEvent]>

Emitted when a new Page is created in the BrowserContext. The event will also fire for popup
pages.
Copy link
Member

Choose a reason for hiding this comment

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

This event will fire for popup pages, shift-clicks, etc.

Copy link
Contributor

@jperl jperl Feb 28, 2020

Choose a reason for hiding this comment

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

Will this event fire if you open a new tab with the browser ui? Tested this locally and it triggers for newPage and pages opened in the UI for chromium (mac-745253) 👍.

docs/api.md Outdated
@@ -1661,6 +1668,13 @@ This method returns all of the dedicated [WebWorkers](https://developer.mozilla.

> **NOTE** This does not contain ServiceWorkers

### class: PageEvent

Event object passed to the listeners of 'pageevent' on 'BrowserContext'. Provides access
Copy link
Member

Choose a reason for hiding this comment

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

Use ```

and ['popup'](link) event of Page

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

src/chromium/crBrowser.ts Show resolved Hide resolved
test/chromium/chromium.spec.js Outdated Show resolved Hide resolved

> **NOTE** Only includes targets from this browser context.
> **NOTE** Only works with persistent context.
Copy link
Contributor

Choose a reason for hiding this comment

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

Any chance you could provide more context on why this only works in persistent context?

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like the background pages are always created in the default context which doesn't work well with browser context level isolation that we want to have. If this becomes a problem we can extend the API in the future.

@dgozman dgozman changed the title [API] chore(chromium): remove Target from public API api(chromium): remove Target from public API Feb 28, 2020
docs/api.md Outdated
@@ -264,6 +264,7 @@ await context.close();

<!-- GEN:toc -->
- [event: 'close'](#event-close)
- [event: 'pageevent'](#event-pageevent)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like the name pageevent. This looks to me like something happened inside the page. What about newpage or pagecreated?

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed to 'page'

@@ -1661,6 +1668,13 @@ This method returns all of the dedicated [WebWorkers](https://developer.mozilla.

> **NOTE** This does not contain ServiceWorkers

### class: PageEvent
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here. What about NewPageEvent?

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'd keep this one as is as it's shorter. Happy to rename if others prefer NewPageEvent or PageCreatedEvent.

docs/api.md Outdated
#### event: 'targetdestroyed'
- <[ChromiumTarget]>
#### event: 'serviceworker'
- <[Page]>
Copy link
Contributor

Choose a reason for hiding this comment

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

Service worker is a page?!

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! Updated.

@yury-s yury-s force-pushed the page-event-targets branch from 53efc49 to 6ea5259 Compare March 2, 2020 21:56
@yury-s yury-s merged commit a57978a into microsoft:master Mar 2, 2020
@yury-s yury-s deleted the page-event-targets branch March 2, 2020 21:58
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.

6 participants