Update chrome.js

This commit is contained in:
Namhyeon Go 2021-06-21 02:54:46 +09:00 committed by GitHub
parent 331578452f
commit 5572edb03d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,9 @@ var FILE = require("lib/file");
var HTTP = require("lib/http"); var HTTP = require("lib/http");
var Websocket = require("lib/websocket"); var Websocket = require("lib/websocket");
// for remote debugging
var pageEventId = 0;
var ChromeObject = function() { var ChromeObject = function() {
this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Google\\Chrome\\Application"; this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Google\\Chrome\\Application";
this.binPath = SYS.getEnvString("PROGRAMFILES") + "\\Google\\:installedDir\\Application\\chrome.exe"; this.binPath = SYS.getEnvString("PROGRAMFILES") + "\\Google\\:installedDir\\Application\\chrome.exe";
@ -23,7 +26,6 @@ var ChromeObject = function() {
// for remote debugging // for remote debugging
this.debuggingPort = 0; this.debuggingPort = 0;
this.pageEventId = 1;
this.pageId = ""; this.pageId = "";
this.ws = Websocket.create(); this.ws = Websocket.create();
@ -196,7 +198,7 @@ var ChromeObject = function() {
this.getPageList = function() { this.getPageList = function() {
if (this.debuggingPort > 0) { if (this.debuggingPort > 0) {
return HTTP.get("http://localhost:" + this.debuggingPort + "/json"); return HTTP.get("http://127.0.0.1:" + this.debuggingPort + "/json");
} else { } else {
console.error("Remote debugging unavailable"); console.error("Remote debugging unavailable");
return []; return [];
@ -224,12 +226,12 @@ var ChromeObject = function() {
this.sendPageRPC = function(method, params) { this.sendPageRPC = function(method, params) {
if (this.pageId != "") { if (this.pageId != "") {
this.ws.send("ws://localhost:" + this.debuggingPort + "/devtools/page/" + this.pageId, JSON.stringify({ this.ws.send("ws://127.0.0.1:" + this.debuggingPort + "/devtools/page/" + this.pageId, JSON.stringify({
"id": this.pageEventId, "id": pageEventId,
"method": method, "method": method,
"params": params "params": params
})); }));
this.pageEventId++; pageEventId++;
console.info("ChromeObject().sendPageRPC() -> Sent"); console.info("ChromeObject().sendPageRPC() -> Sent");
} else { } else {
console.error("pageId not specified"); console.error("pageId not specified");
@ -249,6 +251,10 @@ var ChromeObject = function() {
"expression": expression "expression": expression
}); });
}; };
this.focus = function() {
return this.evaluate("window.focus()");
};
}; };
exports.create = function() { exports.create = function() {