├── .gitignore ├── README.md ├── index.js ├── package.json └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Chrome Remote Protocol Request Interception Test 2 | This repo serves only as a standalone demonstration of how to capture a request. As of writing, this is [currently not working](https://groups.google.com/d/msg/chrome-debugging-protocol/MaIbpNPWqgI/56G3ep-aAwA). 3 | 4 | Created to share with the Chrome team to gain an understanding of if I'm either doing it wrong, or if theres a bug. 5 | 6 | Tested on Mac, Chrome stable and Canary. 7 | 8 | ### Running this example 9 | * **Install dependencies** `yarn install` 10 | * **Run** `node index.js` 11 | 12 | Then, uncomment the `--headless` flag line and try again. 13 | 14 | ![image](https://user-images.githubusercontent.com/39191/27889353-c0584f70-61a0-11e7-9c5a-65e558ee332e.png) 15 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const CRI = require('chrome-remote-interface') 2 | const ChromeLauncher = require('chrome-launcher') 3 | 4 | const go = async () => { 5 | const Chrome = await ChromeLauncher.launch({ 6 | // chromeFlags: ['--headless'], 7 | port: 9222 8 | }) 9 | 10 | const devtools = await CRI() 11 | const { Page, Network } = devtools 12 | 13 | await Promise.all([ 14 | Page.enable(), 15 | Network.enable() 16 | ]) 17 | 18 | await Network.setRequestInterceptionEnabled({ enabled: true }) 19 | 20 | await Page.navigate({ url: 'https://calibreapp.com' }) 21 | 22 | devtools.on('event', message => { 23 | if (message.method === 'Network.requestIntercepted') console.log('intercepted', message) 24 | }) 25 | 26 | Page.loadEventFired(() => Chrome.kill()) 27 | } 28 | 29 | go() 30 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "request-interception", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "repository": "t", 6 | "license": "MIT", 7 | "dependencies": { 8 | "chrome-launcher": "^0.3.0", 9 | "chrome-remote-interface": "^0.24.2" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | "@types/core-js@^0.9.41": 6 | version "0.9.42" 7 | resolved "https://registry.yarnpkg.com/@types/core-js/-/core-js-0.9.42.tgz#dd6da92cd7d5ab5ca0b4477524537c3e633b6bce" 8 | 9 | "@types/mkdirp@^0.3.29": 10 | version "0.3.29" 11 | resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-0.3.29.tgz#7f2ad7ec55f914482fc9b1ec4bb1ae6028d46066" 12 | 13 | "@types/node@6.0.66": 14 | version "6.0.66" 15 | resolved "https://registry.yarnpkg.com/@types/node/-/node-6.0.66.tgz#5680b74a6135d33d4c00447e7c3dc691a4601625" 16 | 17 | chrome-launcher@^0.3.0: 18 | version "0.3.0" 19 | resolved "https://registry.yarnpkg.com/chrome-launcher/-/chrome-launcher-0.3.0.tgz#fe380ed9c4962b758f8ac75ad2b1edda1e3b371d" 20 | dependencies: 21 | "@types/core-js" "^0.9.41" 22 | "@types/mkdirp" "^0.3.29" 23 | "@types/node" "6.0.66" 24 | lighthouse-logger "^1.0.0" 25 | mkdirp "0.5.1" 26 | rimraf "2.2.8" 27 | 28 | chrome-remote-interface@^0.24.2: 29 | version "0.24.2" 30 | resolved "https://registry.yarnpkg.com/chrome-remote-interface/-/chrome-remote-interface-0.24.2.tgz#43a05440a1fa60b73769e72f3e7892ac11d66eba" 31 | dependencies: 32 | commander "2.1.x" 33 | ws "2.0.x" 34 | 35 | commander@2.1.x: 36 | version "2.1.0" 37 | resolved "https://registry.yarnpkg.com/commander/-/commander-2.1.0.tgz#d121bbae860d9992a3d517ba96f56588e47c6781" 38 | 39 | debug@^2.6.8: 40 | version "2.6.8" 41 | resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc" 42 | dependencies: 43 | ms "2.0.0" 44 | 45 | lighthouse-logger@^1.0.0: 46 | version "1.0.0" 47 | resolved "https://registry.yarnpkg.com/lighthouse-logger/-/lighthouse-logger-1.0.0.tgz#c6abdfbbbf0b4a541ab33864802cbad8944bcc8c" 48 | dependencies: 49 | debug "^2.6.8" 50 | 51 | minimist@0.0.8: 52 | version "0.0.8" 53 | resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" 54 | 55 | mkdirp@0.5.1: 56 | version "0.5.1" 57 | resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" 58 | dependencies: 59 | minimist "0.0.8" 60 | 61 | ms@2.0.0: 62 | version "2.0.0" 63 | resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" 64 | 65 | rimraf@2.2.8: 66 | version "2.2.8" 67 | resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.2.8.tgz#e439be2aaee327321952730f99a8929e4fc50582" 68 | 69 | ultron@~1.1.0: 70 | version "1.1.0" 71 | resolved "https://registry.yarnpkg.com/ultron/-/ultron-1.1.0.tgz#b07a2e6a541a815fc6a34ccd4533baec307ca864" 72 | 73 | ws@2.0.x: 74 | version "2.0.3" 75 | resolved "https://registry.yarnpkg.com/ws/-/ws-2.0.3.tgz#532fd499c3f7d7d720e543f1f807106cfc57d9cb" 76 | dependencies: 77 | ultron "~1.1.0" 78 | --------------------------------------------------------------------------------