Update chrome.js

This commit is contained in:
Namhyeon Go 2021-06-20 06:59:41 +09:00 committed by GitHub
parent b3907bd2ed
commit fe435257f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@ var SHELL = require("lib/shell");
var SYS = require("lib/system"); var SYS = require("lib/system");
var FILE = require("lib/file"); var FILE = require("lib/file");
var HTTP = require("lib/http"); var HTTP = require("lib/http");
var Websocket = require("lib/websocket");
var ChromeObject = function() { var ChromeObject = function() {
this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Google\\Chrome\\Application"; this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Google\\Chrome\\Application";
@ -19,7 +20,12 @@ var ChromeObject = function() {
"port": 1080 "port": 1080
}; };
this.inPrivate = false; this.inPrivate = false;
// for remote debugging
this.debuggingPort = 0; this.debuggingPort = 0;
this.pageEventId = 1;
this.pageId = "";
this.ws = Websocket.create();
this.setBinPath = function(path) { this.setBinPath = function(path) {
this.binPath = path; this.binPath = path;
@ -68,6 +74,10 @@ var ChromeObject = function() {
this.setDebuggingPort = function(n) { this.setDebuggingPort = function(n) {
this.debuggingPort = (typeof(n) !== "number" ? this.debuggingPort : n); this.debuggingPort = (typeof(n) !== "number" ? this.debuggingPort : n);
} }
this.setPageId = function(s) {
this.pageId = s;
};
this.createShoutcut = function(url) { this.createShoutcut = function(url) {
if (!this.userDataDir) { if (!this.userDataDir) {
@ -211,6 +221,25 @@ var ChromeObject = function() {
return (x.title == title); return (x.title == title);
}); });
}; };
this.sendRPC = function(method, params) {
this.ws.send("ws://localhost:" + this.debuggingPort + "/devtools/page/" + this.pageId, JSON.stringify({
"id": this.pageEventId,
"method": method,
"params": params
}));
this.pageEventId++;
};
this.navigate = function(url) {
return this.sendRPC("Page.navigate", {
"url": url
});
};
this.evaluate = function(code) {
// todo
};
}; };
exports.create = function() { exports.create = function() {