Skip to content

Instantly share code, notes, and snippets.

@asahasrabuddhe
Last active September 10, 2018 09:48
Show Gist options
  • Save asahasrabuddhe/d8bc054ee207df75a202bc3a3f31f69d to your computer and use it in GitHub Desktop.
Save asahasrabuddhe/d8bc054ee207df75a202bc3a3f31f69d to your computer and use it in GitHub Desktop.
// 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