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

Expose raw protocol in the API #31

Closed
paulirish opened this issue Jun 20, 2017 · 14 comments
Closed

Expose raw protocol in the API #31

paulirish opened this issue Jun 20, 2017 · 14 comments
Labels

Comments

@paulirish
Copy link
Collaborator

While using puppeteer there are still occasions where I want to use the raw protocol.
I'd certainly want to do this against the Page, and potentially the browser as well.

I want to send methods and get responses. Additionally, I want to listen for specific events.

Not sure of the right API and if it needs to be transactional as to not mixup state.

@aslushnikov
Copy link
Contributor

aslushnikov commented Jun 23, 2017

So having just:

var connection = page.connection()

should satisfy the usecase.

@paulirish
Copy link
Collaborator Author

and expose all of what's in https://github.com/GoogleChrome/puppeteer/blob/master/lib/Connection.js ?

i was thinking maybe..

const connection = page.connection();

// send()
const ltree = await connection.send('LayerTree.getLayerTree');

// listen to events
await connection.send('LayerTree.enable');
connection.on('LayerTree.layerTreeChanged', data => { ... });

@paulirish
Copy link
Collaborator Author

Here's a good usecase of why we need to punch through to raw protocol: gr2m/headless-chrome-test#1 Dev wants to toggle offline mode but is currently using simple-headless-chrome

@aslushnikov
Copy link
Contributor

@paulirish It seems to be a good idea to have offline mode in puppeteer to ease service worker testing, filed #63

@paambaati
Copy link

Another use case is using the 'Network.setBlockedURLs` API. I run a crawler with an adblock list that blocks all ads; it would be much simpler to use that instead of using the intercept API and building a regex check for each of my adblock patterns.

@ebidel
Copy link
Contributor

ebidel commented Aug 24, 2017

Anyone working on this? Getting some requests that folks want to go off road. I'd love to recommend a paved path rather than a dirt road :)

@stilliard
Copy link

Currently accessing the raw protocol via page._client like so:

await page._client.send('Log.enable');
page._client.on('Log.entryAdded', console.log);

But the proposed page.connection() sounds like a better solution :)

@aslushnikov
Copy link
Contributor

@ebidel we're working on it!

@ebidel
Copy link
Contributor

ebidel commented Sep 22, 2017

Ping again :)

@karanjthakkar
Copy link

Can I help here?

@JulianKlug
Copy link

Would be good to have for speed testing as well.
Accessing the time every element was loaded would be very useful.

This was referenced Nov 15, 2017
trentmwillis added a commit to trentmwillis/puppeteer that referenced this issue Nov 21, 2017
This patch implements a new page.connection method which exposes an interface for working with the raw protocol.

Fixes puppeteer#31
@trentmwillis
Copy link
Contributor

Since I could also use this feature, I've opened a PR to implement this: #1445.

@Everettss
Copy link

How will it be solved a problem with enabling some services? Currently, there are some services enabled in source code: https://github.com/GoogleChrome/puppeteer/blob/16320b7ac2943aa04420c67e9df367e7801409ea/lib/Page.js#L47-L50

So currently using page._client.send() technique it's hard to know when to use page._client.send('XYZ.enable'). For example:

 // this will work without sending enable
await page._client.send('Network.clearBrowserCache');

// this one require sending enable
await page._client.send('ServiceWorker.enable'); 
await page._client.send('ServiceWorker.unregister', {
    scopeURL: 'http://localhost:8080/',
});

Is page.connection() will cover this problem? Or it will be in documentation when to send enable?

@GregRos
Copy link

GregRos commented Jan 7, 2018

@Everettss Does enabling something twice do anything bad? It could be just best practice to enable something in your application if you want to use it.


I kind of see the problem here. Basically, puppeteer is high-level enough that it needs to keep an internal state, and sending messages via the raw protocol can break that state.

On the other hand, in JavaScript things breaking is just part of life. Raw protocol access should be something that is outlined as dangerous so people will be wary of it and that it can break internal state, but people should still be able to use it because puppeteer will never be able to implement all the functionality of the raw protocol. And if they break something, well, that's what debugging is for.

(From my perspective, using underscored members is not so much dangerous as not a feature of the library so don't use it).

Otherwise, programmers will have to use another library to send raw protocol messages, which will make the likelihood of breaking even higher.

aslushnikov added a commit to aslushnikov/puppeteer that referenced this issue Jan 11, 2018
This patch introduces `target.createCDPSession` method that
allows directly communicating with the target over the
Chrome DevTools Protocol.

Fixes puppeteer#31.
aslushnikov added a commit that referenced this issue Jan 11, 2018
feat: expose raw devtools protocol connection

This patch introduces `target.createCDPSession` method that
allows directly communicating with the target over the
Chrome DevTools Protocol.

Fixes #31.
igorshapiro pushed a commit to WiserSolutions/puppeteer that referenced this issue Jan 16, 2018
feat: expose raw devtools protocol connection

This patch introduces `target.createCDPSession` method that
allows directly communicating with the target over the
Chrome DevTools Protocol.

Fixes puppeteer#31.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests