mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
c0c59383f9
Now that the security review in bug 1542229 and the follow-up work that came out of it is complete, we should go ahead and flip the remote.enabled preference. This patch causes the remote agent to be available to users on the Firefox Nightly release channel. This meansusing --remote-debugger will no longer cause a fatal error Differential Revision: https://phabricator.services.mozilla.com/D55137 --HG-- extra : moz-landing-system : lando
73 lines
1.9 KiB
JavaScript
73 lines
1.9 KiB
JavaScript
"use strict";
|
||
|
||
// Node.js script to test basic CDP behaviors against Firefox and Chromium.
|
||
//
|
||
// Install chrome-remote-interface, the npm package for a CDP client in node:
|
||
//
|
||
// % npm install chrome-remote-interface
|
||
//
|
||
// Run Firefox or Chromium with server turned on:
|
||
//
|
||
// % ./mach run --remote-debugging-port 9222
|
||
// % firefox --remote-debugging-port 9222
|
||
// % chromium-browser --remote-debugging-port=9222
|
||
//
|
||
// Then run this script:
|
||
//
|
||
// % node demo.js
|
||
|
||
const CDP = require("chrome-remote-interface");
|
||
|
||
async function demo() {
|
||
let client;
|
||
try {
|
||
client = await CDP();
|
||
const {Log, Network, Page, Runtime} = client;
|
||
|
||
// Bug 1553756, Firefox requires `contextId` argument to be passed to
|
||
// Runtime.evaluate, so fetch the current context id it first.
|
||
Runtime.enable();
|
||
const { context } = await Runtime.executionContextCreated();
|
||
const contextId = context.id;
|
||
|
||
let { result } = await Runtime.evaluate({
|
||
expression: "this.obj = {foo:true}; this.obj",
|
||
contextId,
|
||
});
|
||
console.log("1", result);
|
||
({ result } = await Runtime.evaluate({
|
||
expression: "this.obj",
|
||
contextId,
|
||
}));
|
||
console.log("2", result);
|
||
({ result } = await Runtime.evaluate({
|
||
expression: "this.obj.foo",
|
||
contextId,
|
||
}));
|
||
console.log("3", result);
|
||
|
||
// receive console.log messages and print them
|
||
Log.enable();
|
||
Log.entryAdded(({entry}) => {
|
||
const {timestamp, level, text, args} = entry;
|
||
const msg = text || args.join(" ");
|
||
console.log(`${new Date(timestamp)}\t${level.toUpperCase()}\t${msg}`);
|
||
});
|
||
|
||
// turn on navigation related events, such as DOMContentLoaded et al.
|
||
await Page.enable();
|
||
|
||
const onLoad = Page.loadEventFired();
|
||
await Page.navigate({url: "data:text/html,test-page<script>console.log('foo');</script><script>'</script>"});
|
||
await onLoad;
|
||
} catch (e) {
|
||
console.error(e);
|
||
} finally {
|
||
if (client) {
|
||
await client.close();
|
||
}
|
||
}
|
||
}
|
||
|
||
demo();
|