This repository has been archived by the owner on Feb 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
embed.js
41 lines (36 loc) · 1.42 KB
/
embed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var ChromeRemoteInterface = require('chrome-remote-interface');
//var MultiplexServer = require("chrome-remote-multiplex").MultiplexServer;
var MultiplexServer = require("..").MultiplexServer;
var server = new MultiplexServer({
logging: "debug"
});
var remoteClient = null;
server.listen()
.then(() => {
console.log("Connecting client to headless chrome ...");
return ChromeRemoteInterface({ port: server.options.listenPort })
.then((_remoteClient) => {
remoteClient = _remoteClient;
remoteClient.Network.requestWillBeSent(params => {
console.log("REQUEST: " + params.request.url);
});
remoteClient.Runtime.consoleAPICalled((entry) => {
var str = "";
entry.args.forEach(function(ro) {
str += " " + ro.value;
});
console.log("CONSOLE API: " + entry.type + " " + str);
return remoteClient.Runtime.discardConsoleEntries();
});
// enable events then start!
return Promise.all([ remoteClient.Network.enable(), remoteClient.Page.enable(), remoteClient.Runtime.enable() ]);
});
})
.then(function() {
console.log("Visiting URL ...");
return remoteClient.Page.navigate({ url: "http://www.google.co.uk" });
})
.then(() => {
return new Promise((resolve, reject) => setTimeout(resolve, 1500));
})
.catch((err) => console.log("Error while talking to Chrome: " + err));