Last active
September 10, 2018 09:48
-
-
Save asahasrabuddhe/d8bc054ee207df75a202bc3a3f31f69d to your computer and use it in GitHub Desktop.
This file contains 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
// Enable target discovery | |
await Target.setDiscoverTargets({ | |
discover: true | |
}); | |
// The following function is invoked anytime a tab is created. | |
Target.targetCreated((params) => { | |
// If the target is not a page, return | |
if (params.targetInfo.type !== 'page') { | |
return; | |
} | |
// Extract the ID of the new Tab from event params. | |
const { targetId } = params.targetInfo; | |
// search for the desired tab in list of all tabs. | |
const findTarget = (targets) => { | |
return targets.find(target => target.id === targetId); | |
}; | |
// Connect to the newly opened tab | |
CDP({ target: findTarget }, async popup => { | |
// Set download behavior | |
popup.Page.setDownloadBehavior({ | |
behavior: 'allow', | |
downloadPath: '/path/to/download' | |
}); | |
// Monitor requests | |
popup.Network.requestWillBeSent((params) => { | |
console.log("PPP:", params.request.url); | |
}); | |
await popup.Page.enable(); | |
await popup.Network.enable(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment