Skip to content
This repository has been archived by the owner on Nov 24, 2018. It is now read-only.

Implement an onConsoleMessage() event #206

Open
ylscsdb opened this issue Aug 9, 2017 · 6 comments
Open

Implement an onConsoleMessage() event #206

ylscsdb opened this issue Aug 9, 2017 · 6 comments

Comments

@ylscsdb
Copy link

ylscsdb commented Aug 9, 2017

.evaluate(() => {
         console.log('aaaa') // Could console be  effected in function 'evaluate() '
        })
@justincy
Copy link

justincy commented Aug 9, 2017

Yes.

evaluate(): Evaluate Javascript code within Chrome in the context of the DOM.

You can access anything you normally would be able to via script injected on the page, because that's what's being done here. The method you pass to evaluate() is serialized, injected into the page, and then executed.

@ylscsdb
Copy link
Author

ylscsdb commented Aug 10, 2017

Yes, I know. I think if there is a method to catch the log executed in the page.

 chromeless.evaluate(() => {
            $("button").click();
            console.info($("button"))
        });
chromeless.onConsoleMessage=(msg) =>  {
        console.log(msg);
};//a method to catch the log executed in the page. 

@justincy
Copy link

I see. Yes, that would be nice. I've wanted that too.

@adieuadieu adieuadieu changed the title Could console be effected in function 'evaluate() ' Implement an onConsole() event Aug 12, 2017
@adieuadieu
Copy link
Collaborator

I guess what you're looking for is access to Console.messageAdded?

@adieuadieu adieuadieu changed the title Implement an onConsole() event Implement an onConsoleMessage() event Aug 12, 2017
@elisherer
Copy link
Contributor

Actually Console is deprecated, use Log.entryAdded (experimental) or Runtime.consoleAPICalled instead.

@up9cloud
Copy link

Hi, is there a clean way to get the client (CDP) from chromeless instance?

just wanna do like this...

const chromeless = new Chromeless()

const client = ? // o.o?

const { Runtime } = client
Runtime.consoleAPICalled(({ type, args }) => {
  console[type].apply(console, args.map(o => o.value))
})

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants