Created
March 6, 2017 09:03
-
-
Save joelalejandro/2f915698cb7e9db3178449e9de758a81 to your computer and use it in GitHub Desktop.
Karma + Gulp + PhantomJS + chrome-remote-interface
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
| module.exports = (remote /* ... and some irrelevant dependencies */) => { | |
| const traceCategories = [ | |
| '-*', | |
| 'devtools.timeline', | |
| 'disabled-by-default-devtools.timeline', | |
| 'disabled-by-default-devtools.timeline.frame', | |
| 'toplevel', | |
| 'blink.console', | |
| 'disabled-by-default-devtools.timeline.stack', | |
| 'disabled-by-default-devtools.screenshot', | |
| 'disabled-by-default-v8.cpu_profile', | |
| ]; | |
| let eventData = []; | |
| (function connect() { | |
| remote({ | |
| tab: 'ws://localhost:9222/devtools/page/1', | |
| }, (chrome) => { | |
| const { Page, Tracing } = chrome; | |
| Page.enable(); | |
| // ------------------------------------------- | |
| Tracing.start({ | |
| categories: traceCategories.join(', '), | |
| options: 'sampling-frequency=10000', | |
| }); // ----------------- PhantomJS fails here. | |
| Page.navigate({ url: '<SOMEWHERE>' }); | |
| Page.loadEventFired(() => { Tracing.end(); }); | |
| Tracing.dataCollected((data) => { | |
| eventData = eventData.concat(data.value); | |
| }); | |
| Tracing.tracingComplete(() => { | |
| // Do something with this. | |
| }); | |
| }).on('error', (err) => { | |
| console.log('reattempting connection'); | |
| setTimeout(connect, 1000); | |
| }); | |
| })(); | |
| }; |
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('./cdp'); | |
| const remote = require('chrome-remote-interface'); | |
| // ... other tasks ... | |
| gulp.task('some:task', () => { | |
| // Assume {server} a Karma server started via Node. | |
| server.on('browsers_ready', () => { | |
| cdp(remote /* and other injectable dependencies */); | |
| }); | |
| }); |
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
| // Karma configuration | |
| module.exports = function (config) { | |
| config.set({ | |
| // ...all default settings... // | |
| browsers: ['PhantomJS_Suri'], | |
| customLaunchers: { | |
| /** | |
| * Configuration based on https://github.com/paulirish/automated-chrome-profiling | |
| */ | |
| 'PhantomJS_Suri': { | |
| base: 'PhantomJS', | |
| flags: [ | |
| '--remote-debugger-port=9222', | |
| '--remote-debugger-autorun=true', | |
| ], | |
| }, | |
| }, | |
| // Continuous Integration mode | |
| // if true, Karma captures browsers, runs the tests and exits | |
| singleRun: true, | |
| }); | |
| }; |
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
| (node:40632) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: 'Tracing.start' wasn't found |
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
| Chrome { | |
| domain: null, | |
| _events: {}, | |
| _eventsCount: 0, | |
| _maxListeners: undefined, | |
| host: 'localhost', | |
| port: 9222, | |
| protocol: | |
| { version: { major: '1', minor: '2' }, | |
| remote: false, | |
| tab: 'ws://localhost:9222/devtools/page/1', | |
| _notifier: | |
| EventEmitter { | |
| domain: null, | |
| _events: { connect: [Function], error: [Function] }, | |
| _eventsCount: 2, | |
| _maxListeners: undefined }, | |
| _callbacks: {}, | |
| _nextCommandId: 1, | |
| Inspector: | |
| Memory: | |
| Page: | |
| Rendering: | |
| Emulation: | |
| Security: | |
| Network: | |
| Database: | |
| IndexedDB: | |
| CacheStorage: | |
| DOMStorage: | |
| ApplicationCache: | |
| DOM: | |
| CSS: | |
| IO: | |
| DOMDebugger: | |
| Target: | |
| ServiceWorker: | |
| Input: | |
| LayerTree: | |
| DeviceOrientation: | |
| Tracing: | |
| { start: | |
| { [Function: handler] | |
| category: 'command', | |
| description: 'Start trace events collection.', | |
| parameters: [Object] }, | |
| end: | |
| { [Function: handler] | |
| category: 'command', | |
| description: 'Stop trace events collection.' }, | |
| getCategories: | |
| { [Function: handler] | |
| category: 'command', | |
| description: 'Gets supported tracing categories.', | |
| returns: [Object] }, | |
| requestMemoryDump: | |
| { [Function: handler] | |
| category: 'command', | |
| description: 'Request a global memory dump.', | |
| returns: [Object] }, | |
| recordClockSyncMarker: | |
| { [Function: handler] | |
| category: 'command', | |
| description: 'Record a clock sync marker in the trace.', | |
| parameters: [Object] }, | |
| dataCollected: | |
| { [Function: handler] | |
| category: 'event', | |
| parameters: [Object], | |
| description: 'Contains an bucket of collected trace events. When tracing is stopped collected events will be send as a sequence of dataCollected events followed by tracingComplete event.' }, | |
| tracingComplete: | |
| { [Function: handler] | |
| category: 'event', | |
| description: 'Signals that tracing is stopped and there is no trace buffers pending flush, all data were delivered via dataCollected events.', | |
| parameters: [Object] }, | |
| bufferUsage: { [Function: handler] category: 'event', parameters: [Object] }, | |
| MemoryDumpConfig: | |
| { category: 'type', | |
| id: 'MemoryDumpConfig', | |
| type: 'object', | |
| description: 'Configuration for memory dump. Used only when "memory-infra" category is enabled.' }, | |
| TraceConfig: | |
| { category: 'type', | |
| id: 'TraceConfig', | |
| type: 'object', | |
| properties: [Object] } }, | |
| Animation: | |
| Accessibility: | |
| Storage: | |
| Log: | |
| SystemInfo: | |
| Tethering: | |
| Schema: | |
| Runtime: | |
| Debugger: | |
| Console: | |
| Profiler: | |
| HeapProfiler: } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment