-
-
Save codesorter2015/1592cfcd8cca0ffc51bbb1f4b8f0fcdf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const CDP = require('chrome-remote-interface'); | |
CDP(async (client) => { | |
const {Network, Page, Target} = client; | |
Network.requestWillBeSent(({request, redirectResponse}) => { | |
console.log((redirectResponse || {}).url + ' -> ' + request.url); | |
}); | |
Target.targetCreated((params) => { | |
if(params.targetInfo.type != "page") { | |
return; | |
} | |
const {targetId} = params.targetInfo; | |
const findTarget = (targets) => { | |
return targets.find(target => target.id === targetId); | |
}; | |
CDP({target: findTarget}, async (popup) => { | |
popup.Network.requestWillBeSent(({request, redirectResponse}) => { | |
console.log((redirectResponse || {}).url + ' -> ' + request.url); | |
}); | |
await popup.Network.enable(); | |
await popup.Runtime.runIfWaitingForDebugger(); | |
}); | |
}); | |
try { | |
await Target.setDiscoverTargets({discover: true}); | |
Target.setAutoAttach({ | |
autoAttach: true, | |
waitForDebuggerOnStart: true | |
}); | |
await Network.enable(); | |
await Page.enable(); | |
await Page.navigate({url: 'http://getresto.gifts48.ru/1/'}); | |
await Page.loadEventFired(); | |
clickPage(client); | |
} catch (err) { | |
console.error(err); | |
} finally { | |
// client.close(); | |
} | |
}).on('error', (err) => { | |
console.error(err); | |
}); | |
function clickPage(client) { | |
const options = { | |
x: 100, | |
y: 100, | |
button: 'left', | |
clickCount: 1 | |
}; | |
Promise.resolve().then(() => { | |
options.type = 'mousePressed'; | |
return client.Input.dispatchMouseEvent(options); | |
}).then(() => { | |
options.type = 'mouseReleased'; | |
return client.Input.dispatchMouseEvent(options); | |
}).catch((err) => { | |
console.error(err); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment