gpt-driver-node 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +30 -20
- package/dist/index.mjs +30 -20
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1487,31 +1487,40 @@ ${"=".repeat(50)}`);
|
|
|
1487
1487
|
globalLogger.debug("Capturing screenshot...");
|
|
1488
1488
|
let screenshot;
|
|
1489
1489
|
if (appiumSessionConfig.platform === "Android") {
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1490
|
+
const serverHostname = new URL(appiumSessionConfig.serverUrl).hostname;
|
|
1491
|
+
const isLocalhost = serverHostname === "localhost" || serverHostname === "127.0.0.1" || serverHostname === "::1";
|
|
1492
|
+
let rawBuffer;
|
|
1493
|
+
if (isLocalhost) {
|
|
1494
|
+
try {
|
|
1495
|
+
const { execSync } = await import('node:child_process');
|
|
1496
|
+
let udid;
|
|
1497
|
+
if (this.driver) {
|
|
1498
|
+
if (this.driver.sessionId != null) {
|
|
1499
|
+
const caps = this.driver.capabilities;
|
|
1500
|
+
udid = caps["appium:udid"] || caps["udid"];
|
|
1501
|
+
} else {
|
|
1502
|
+
const driver = this.driver;
|
|
1503
|
+
const capabilities = await driver.getCapabilities();
|
|
1504
|
+
udid = capabilities.get("appium:udid") || capabilities.get("udid");
|
|
1505
|
+
}
|
|
1501
1506
|
}
|
|
1507
|
+
const deviceArg = udid ? `-s ${udid}` : "";
|
|
1508
|
+
rawBuffer = execSync(`adb ${deviceArg} exec-out screencap -p`, {
|
|
1509
|
+
encoding: "buffer",
|
|
1510
|
+
maxBuffer: 50 * 1024 * 1024
|
|
1511
|
+
});
|
|
1512
|
+
} catch (e) {
|
|
1513
|
+
globalLogger.warn("ADB screenshot failed, falling back to Appium screenshot");
|
|
1514
|
+
const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/screenshot`);
|
|
1515
|
+
const screenshotResponse = await axios.get(url);
|
|
1516
|
+
rawBuffer = Buffer.from(screenshotResponse.data.value, "base64");
|
|
1502
1517
|
}
|
|
1503
|
-
|
|
1504
|
-
const buffer = execSync(`adb ${deviceArg} exec-out screencap -p`, {
|
|
1505
|
-
encoding: "buffer",
|
|
1506
|
-
maxBuffer: 50 * 1024 * 1024
|
|
1507
|
-
});
|
|
1508
|
-
screenshot = buffer.toString("base64");
|
|
1509
|
-
} catch (e) {
|
|
1510
|
-
globalLogger.warn("ADB screenshot failed, falling back to Appium screenshot");
|
|
1518
|
+
} else {
|
|
1511
1519
|
const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/screenshot`);
|
|
1512
1520
|
const screenshotResponse = await axios.get(url);
|
|
1513
|
-
|
|
1521
|
+
rawBuffer = Buffer.from(screenshotResponse.data.value, "base64");
|
|
1514
1522
|
}
|
|
1523
|
+
screenshot = (await sharp(rawBuffer).jpeg({ quality: 80 }).toBuffer()).toString("base64");
|
|
1515
1524
|
} else {
|
|
1516
1525
|
const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/screenshot`);
|
|
1517
1526
|
const screenshotResponse = await axios.get(url);
|
|
@@ -1621,6 +1630,7 @@ ${"=".repeat(50)}`);
|
|
|
1621
1630
|
globalLogger.debug(`[Performance] Smart loop completed in ${(smartLoopEndTime - smartLoopStartTime).toFixed(2)}ms`);
|
|
1622
1631
|
if (!result.success) {
|
|
1623
1632
|
await this.setSessionFailed();
|
|
1633
|
+
throw new Error(`Smart loop failed: ${result.error}`);
|
|
1624
1634
|
}
|
|
1625
1635
|
if (result.cacheHitCount) {
|
|
1626
1636
|
this._stats_cacheHits += result.cacheHitCount;
|
package/dist/index.mjs
CHANGED
|
@@ -1485,31 +1485,40 @@ ${"=".repeat(50)}`);
|
|
|
1485
1485
|
globalLogger.debug("Capturing screenshot...");
|
|
1486
1486
|
let screenshot;
|
|
1487
1487
|
if (appiumSessionConfig.platform === "Android") {
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1488
|
+
const serverHostname = new URL(appiumSessionConfig.serverUrl).hostname;
|
|
1489
|
+
const isLocalhost = serverHostname === "localhost" || serverHostname === "127.0.0.1" || serverHostname === "::1";
|
|
1490
|
+
let rawBuffer;
|
|
1491
|
+
if (isLocalhost) {
|
|
1492
|
+
try {
|
|
1493
|
+
const { execSync } = await import('node:child_process');
|
|
1494
|
+
let udid;
|
|
1495
|
+
if (this.driver) {
|
|
1496
|
+
if (this.driver.sessionId != null) {
|
|
1497
|
+
const caps = this.driver.capabilities;
|
|
1498
|
+
udid = caps["appium:udid"] || caps["udid"];
|
|
1499
|
+
} else {
|
|
1500
|
+
const driver = this.driver;
|
|
1501
|
+
const capabilities = await driver.getCapabilities();
|
|
1502
|
+
udid = capabilities.get("appium:udid") || capabilities.get("udid");
|
|
1503
|
+
}
|
|
1499
1504
|
}
|
|
1505
|
+
const deviceArg = udid ? `-s ${udid}` : "";
|
|
1506
|
+
rawBuffer = execSync(`adb ${deviceArg} exec-out screencap -p`, {
|
|
1507
|
+
encoding: "buffer",
|
|
1508
|
+
maxBuffer: 50 * 1024 * 1024
|
|
1509
|
+
});
|
|
1510
|
+
} catch (e) {
|
|
1511
|
+
globalLogger.warn("ADB screenshot failed, falling back to Appium screenshot");
|
|
1512
|
+
const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/screenshot`);
|
|
1513
|
+
const screenshotResponse = await axios.get(url);
|
|
1514
|
+
rawBuffer = Buffer.from(screenshotResponse.data.value, "base64");
|
|
1500
1515
|
}
|
|
1501
|
-
|
|
1502
|
-
const buffer = execSync(`adb ${deviceArg} exec-out screencap -p`, {
|
|
1503
|
-
encoding: "buffer",
|
|
1504
|
-
maxBuffer: 50 * 1024 * 1024
|
|
1505
|
-
});
|
|
1506
|
-
screenshot = buffer.toString("base64");
|
|
1507
|
-
} catch (e) {
|
|
1508
|
-
globalLogger.warn("ADB screenshot failed, falling back to Appium screenshot");
|
|
1516
|
+
} else {
|
|
1509
1517
|
const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/screenshot`);
|
|
1510
1518
|
const screenshotResponse = await axios.get(url);
|
|
1511
|
-
|
|
1519
|
+
rawBuffer = Buffer.from(screenshotResponse.data.value, "base64");
|
|
1512
1520
|
}
|
|
1521
|
+
screenshot = (await sharp(rawBuffer).jpeg({ quality: 80 }).toBuffer()).toString("base64");
|
|
1513
1522
|
} else {
|
|
1514
1523
|
const url = buildUrl(this.appiumSessionConfig.serverUrl, `/session/${this.appiumSessionConfig.id}/screenshot`);
|
|
1515
1524
|
const screenshotResponse = await axios.get(url);
|
|
@@ -1619,6 +1628,7 @@ ${"=".repeat(50)}`);
|
|
|
1619
1628
|
globalLogger.debug(`[Performance] Smart loop completed in ${(smartLoopEndTime - smartLoopStartTime).toFixed(2)}ms`);
|
|
1620
1629
|
if (!result.success) {
|
|
1621
1630
|
await this.setSessionFailed();
|
|
1631
|
+
throw new Error(`Smart loop failed: ${result.error}`);
|
|
1622
1632
|
}
|
|
1623
1633
|
if (result.cacheHitCount) {
|
|
1624
1634
|
this._stats_cacheHits += result.cacheHitCount;
|