重构浏览器自动化后端代码结构

This commit is contained in:
fofolee
2025-01-23 18:43:44 +08:00
parent df8c6c48f8
commit 179c0c567f
11 changed files with 612 additions and 575 deletions

View File

@@ -0,0 +1,23 @@
const { initCDP, cleanupCDP } = require("./cdp");
const { searchTarget } = require("./tabs");
const getUrl = async (tab) => {
const target = await searchTarget(tab);
const { Page } = await initCDP(target.id);
const { frameTree } = await Page.getFrameTree();
await cleanupCDP(target.id);
return frameTree.frame.url;
};
const setUrl = async (tab, url) => {
const target = await searchTarget(tab);
const { Page } = await initCDP(target.id);
await Page.navigate({ url });
await Page.loadEventFired();
await cleanupCDP(target.id);
};
module.exports = {
getUrl,
setUrl,
};