@midscene/web 0.8.9 → 0.8.10-beta-20241225120902.0
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/es/chrome-extension.js +42 -49
- package/dist/es/index.js +3047 -60
- package/dist/es/puppeteer.js +115 -2
- package/dist/es/yaml.js +3030 -0
- package/dist/lib/chrome-extension.js +42 -49
- package/dist/lib/index.js +3047 -60
- package/dist/lib/puppeteer.js +115 -2
- package/dist/lib/yaml.js +3030 -0
- package/dist/types/appium.d.ts +2 -3
- package/dist/types/chrome-extension.d.ts +4 -5
- package/dist/types/debug.d.ts +2 -3
- package/dist/types/index.d.ts +4 -4
- package/dist/types/{page-6aae9cb4.d.ts → page-27ccaf27.d.ts} +3 -4
- package/dist/types/playground.d.ts +4 -5
- package/dist/types/playwright.d.ts +5 -5
- package/dist/types/puppeteer.d.ts +16 -4
- package/dist/types/{tasks-dbcd0887.d.ts → tasks-c7e3abf6.d.ts} +1 -1
- package/dist/types/utils-e11cb403.d.ts +33 -0
- package/dist/types/utils.d.ts +1 -2
- package/dist/types/yaml.d.ts +14 -0
- package/package.json +11 -5
|
@@ -1945,33 +1945,11 @@ var scriptFileContent = async () => {
|
|
|
1945
1945
|
}
|
|
1946
1946
|
return import_node_fs3.default.readFileSync(scriptFileToRetrieve, "utf8");
|
|
1947
1947
|
};
|
|
1948
|
-
var lastTwoCallTime = [0, 0];
|
|
1949
|
-
var callInterval = 1050;
|
|
1950
|
-
async function getScreenshotBase64FromWindowId(windowId) {
|
|
1951
|
-
const activeWindow = await chrome.windows.getAll({ populate: true });
|
|
1952
|
-
if (activeWindow.find((w) => w.id === windowId) === void 0) {
|
|
1953
|
-
throw new Error(`Window with id ${windowId} is not active`);
|
|
1954
|
-
}
|
|
1955
|
-
const now = Date.now();
|
|
1956
|
-
if (now - lastTwoCallTime[0] < callInterval) {
|
|
1957
|
-
const sleepTime = callInterval - (now - lastTwoCallTime[0]);
|
|
1958
|
-
console.warn(
|
|
1959
|
-
`Sleep for ${sleepTime}ms to avoid too frequent screenshot calls`
|
|
1960
|
-
);
|
|
1961
|
-
await new Promise((resolve) => setTimeout(resolve, sleepTime));
|
|
1962
|
-
}
|
|
1963
|
-
const base64 = await chrome.tabs.captureVisibleTab(windowId, {
|
|
1964
|
-
format: "jpeg",
|
|
1965
|
-
quality: 70
|
|
1966
|
-
});
|
|
1967
|
-
lastTwoCallTime.shift();
|
|
1968
|
-
lastTwoCallTime.push(Date.now());
|
|
1969
|
-
return base64;
|
|
1970
|
-
}
|
|
1971
1948
|
var ChromeExtensionProxyPage = class {
|
|
1972
1949
|
constructor(tabId, windowId) {
|
|
1973
1950
|
this.pageType = "chrome-extension-proxy";
|
|
1974
1951
|
this.debuggerAttached = false;
|
|
1952
|
+
this.attachingDebugger = null;
|
|
1975
1953
|
this.mouse = {
|
|
1976
1954
|
click: async (x, y) => {
|
|
1977
1955
|
await this.sendCommandToDebugger("Input.dispatchMouseEvent", {
|
|
@@ -2026,14 +2004,25 @@ var ChromeExtensionProxyPage = class {
|
|
|
2026
2004
|
async attachDebugger() {
|
|
2027
2005
|
if (this.debuggerAttached)
|
|
2028
2006
|
return;
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2007
|
+
if (this.attachingDebugger) {
|
|
2008
|
+
await this.attachingDebugger;
|
|
2009
|
+
return;
|
|
2010
|
+
}
|
|
2011
|
+
this.attachingDebugger = (async () => {
|
|
2012
|
+
try {
|
|
2013
|
+
await chrome.debugger.attach({ tabId: this.tabId }, "1.3");
|
|
2014
|
+
this.debuggerAttached = true;
|
|
2015
|
+
chrome.debugger.onEvent.addListener((source, method, params) => {
|
|
2016
|
+
console.log("debugger event", source, method, params);
|
|
2017
|
+
if (method === "Debugger.detached") {
|
|
2018
|
+
this.debuggerAttached = false;
|
|
2019
|
+
}
|
|
2020
|
+
});
|
|
2021
|
+
} finally {
|
|
2022
|
+
this.attachingDebugger = null;
|
|
2035
2023
|
}
|
|
2036
|
-
});
|
|
2024
|
+
})();
|
|
2025
|
+
await this.attachingDebugger;
|
|
2037
2026
|
}
|
|
2038
2027
|
async detachDebugger() {
|
|
2039
2028
|
if (!this.debuggerAttached)
|
|
@@ -2073,23 +2062,24 @@ var ChromeExtensionProxyPage = class {
|
|
|
2073
2062
|
}
|
|
2074
2063
|
return returnValue.result.value;
|
|
2075
2064
|
}
|
|
2076
|
-
async rectOfNodeId(nodeId) {
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
}
|
|
2065
|
+
// private async rectOfNodeId(nodeId: number): Promise<Rect | null> {
|
|
2066
|
+
// try {
|
|
2067
|
+
// const { model } =
|
|
2068
|
+
// await this.sendCommandToDebugger<CDPTypes.DOM.GetBoxModelResponse>(
|
|
2069
|
+
// 'DOM.getBoxModel',
|
|
2070
|
+
// { nodeId },
|
|
2071
|
+
// );
|
|
2072
|
+
// return {
|
|
2073
|
+
// left: model.border[0],
|
|
2074
|
+
// top: model.border[1],
|
|
2075
|
+
// width: model.border[2] - model.border[0],
|
|
2076
|
+
// height: model.border[5] - model.border[1],
|
|
2077
|
+
// };
|
|
2078
|
+
// } catch (error) {
|
|
2079
|
+
// console.error('Error getting box model for nodeId', nodeId, error);
|
|
2080
|
+
// return null;
|
|
2081
|
+
// }
|
|
2082
|
+
// }
|
|
2093
2083
|
async getElementInfos() {
|
|
2094
2084
|
const content = await this.getPageContentByCDP();
|
|
2095
2085
|
if (content == null ? void 0 : content.size) {
|
|
@@ -2104,8 +2094,11 @@ var ChromeExtensionProxyPage = class {
|
|
|
2104
2094
|
return content.size;
|
|
2105
2095
|
}
|
|
2106
2096
|
async screenshotBase64() {
|
|
2107
|
-
const base64 = await
|
|
2108
|
-
|
|
2097
|
+
const base64 = await this.sendCommandToDebugger("Page.captureScreenshot", {
|
|
2098
|
+
format: "jpeg",
|
|
2099
|
+
quality: 70
|
|
2100
|
+
});
|
|
2101
|
+
return `data:image/jpeg;base64,${base64.data}`;
|
|
2109
2102
|
}
|
|
2110
2103
|
async url() {
|
|
2111
2104
|
const url = await chrome.tabs.get(this.tabId).then((tab) => tab.url);
|