MCPcopy Index your code
hub / github.com/browsemake/browser-cli / resolveAndPerformAction

Function resolveAndPerformAction

daemon.js:110–132  ·  view source on GitHub ↗
(req, res, actionFn, recordAction, recordArgs = {})

Source from the content-addressed store, hash-verified

108 });
109
110 async function resolveAndPerformAction(req, res, actionFn, recordAction, recordArgs = {}) {
111 let { selector } = req.body;
112 if (!selector) return res.status(400).send('missing selector');
113
114 try {
115 if (!isNaN(selector) && !isNaN(parseFloat(selector))) {
116 const xpath = lastIdToXPath[selector];
117 if (!xpath) return res.status(400).send('XPath not found for ID');
118 selector = xpath;
119 }
120 const element = await getActivePage().$('xpath=' + selector);
121 if (!element) {
122 return res.status(400).send(`Element not found for selector: ${selector}`);
123 }
124 await actionFn(selector);
125 record(recordAction, { selector, ...recordArgs });
126 res.send('ok');
127 } catch (err) {
128 res.status(500).send(`Error when action: ${err.message}
129
130If you want to use ID instead of XPath, use 60 instead of #60 or [60]`);
131 }
132 }
133
134 app.post('/scroll-into-view', async (req, res) => {
135 await resolveAndPerformAction(req, res, async (selector) => {

Callers 1

daemon.jsFile · 0.85

Calls 2

getActivePageFunction · 0.85
recordFunction · 0.85

Tested by

no test coverage detected