OnetapInc / chromy

Chromy is a library for operating headless chrome. 🍺🍺🍺
MIT License
605 stars 41 forks source link

activate tab by targetId #48

Closed cjhuaxin closed 6 years ago

cjhuaxin commented 6 years ago

Hi, in my project, the chromy has multiple tabs, I'm tring to change the activate tab by targetId. this is my code:

let pages = await chromy.getPageTargets();
let targetPage = pages.filter(p => p.url.indexOf(someKeys) > -1)[0];
await chromy.Target.activateTarget({targetId: targetPage.targetId});

but I got some errors like this: TypeError: Cannot read property 'activateTarget' of undefined

Is there any way to activate the other tab? Thanks in advance!

cjhuaxin commented 6 years ago

I found the solution, just add the launchBrowser: false option, this is code:

let pages = await chromy.getPageTargets();
let targetPage = pages.filter(p => p.url.indexOf(someKeys) > -1)[0];
chromy = await new Chromy({target: targetPage.targetId, activateOnStartUp: true, launchBrowser: false});

Thanks the examples

dotneet commented 6 years ago

That's good! If you have another question open an issue anytime.