提交 9a5068b7 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

chore(automator): program.tap

上级 d42e853d
"use strict";var e=require("debug"),t=require("postcss-selector-parser"),o=require("fs");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=r(e),a=r(t),s=r(o);const i=n.default("automator:devtool");function c(e){e.walk((e=>{if("tag"===e.type){const t=e.value;e.value="page"===t?"uni-page-body":"uni-"+t}}))}const l=["Page.getElement","Page.getElements","Element.getElement","Element.getElements"];function p(e){try{return require(e)}catch(t){return require(require.resolve(e,{paths:[process.cwd()]}))}}/^win/.test(process.platform);const u=["chromium","firefox","webkit"];let f=!1;try{f=!!p("playwright")}catch(e){}const w=new Map;function h(e="chromium"){const t=e&&u.includes(e)?e:u[0];let o=w.get(t);return o||(o=function(e){if("webkit"===e)return d("webkit");if("firefox"===e)return d("firefox");if(f)return d("chromium");throw new Error("Playwright dependency not found, please install playwright!")}(t),w.set(t,o)),o}function d(e){const t=p("playwright");let o,r;return{type:e,provider:"playwright",async open(n,a,s){o=await t[e].launch(a.options),"firefox"===e&&(a.contextOptions.isMobile=!1),i(`browser.newContext ${JSON.stringify(a.contextOptions)}`);const c=await o.newContext(a.contextOptions);r=await c.newPage(),r.on("console",(e=>{s.emit("App.logAdded",{type:e.type(),args:[e.text()]})})),r.on("pageerror",(e=>{s.emit("App.exceptionThrown",e)})),await r.goto(a.url||n),await r.waitForTimeout(1e3)},close:()=>o.close(),screenshot:(e=!1)=>r.screenshot({fullPage:e}).then((e=>e.toString("base64"))),swipe:e=>new Promise((async t=>{const{startPoint:o,endPoint:n}=e;await r.evaluate((([e,t])=>{window.scrollBy({left:e.x-t.x,top:e.y-t.y,behavior:"smooth"})}),[o,n]),t("swipe success")}))}}let g;const y={"Tool.close":{reflect:async()=>{await g.close()}},"App.exit":{reflect:async()=>{}},"App.enableLog":{reflect:()=>Promise.resolve()},"App.captureScreenshot":{reflect:async(e,t)=>{const o=await g.screenshot(!!t.fullPage);return i(`App.captureScreenshot ${o.length}`),{data:o}}},"App.swipe":{reflect:async(e,t)=>{const o=await g.swipe(t);return i(`App.swipe ${o.length}`),{data:o}}}};!function(e){l.forEach((t=>{e[t]=function(e){return{reflect:async(t,o)=>t(e,o,!1),params:e=>(e.selector&&(e.selector=a.default(c).processSync(e.selector)),e)}}(t)}))}(y);const m={devtools:{name:"browser",paths:[],validate:async function(e){return e.options=e.options||{},e.executablePath&&!e.options.executablePath&&(e.options.executablePath=e.executablePath),e.contextOptions={viewport:Object.assign({width:375,height:667},e.options.defaultViewport||{}),hasTouch:!0,isMobile:!0,deviceScaleFactor:2},e.options.defaultViewport=Object.assign({width:375,height:667,deviceScaleFactor:2,hasTouch:!0,isMobile:!0},e.options.defaultViewport||{}),e.teardown||(e.teardown=!1===e.options.headless?"disconnect":"close"),e},create:async function(e,t,o){t.executablePath?await new Promise(((o,r)=>{const{exec:n}=require("node:child_process");if(/^win/.test(process.platform)){const r="C:\\Users\\Public\\AppData\\Local\\chrome";s.default.existsSync(r)||s.default.mkdirSync(r,{recursive:!0}),n(`start ${t.executablePath} --user-data-dir=${r} ${e}`,(e=>{if(e)throw console.error(`open ${t.executablePath} fail, ${e}`),Error(e)})),setTimeout((()=>{o(null)}),1e3)}else n(`open -a "${t.executablePath}" ${e}`,(e=>{e&&(console.error(`open ${t.executablePath} fail, ${e}`),r(e)),o(null)}))})):(g=h(process.env.BROWSER),i("createDevtools "+(g.provider+" "+g.type+" "+JSON.stringify(t))),await g.open(e,t,o))}},shouldCompile:(e,t)=>!t.url,adapter:y};module.exports=m;
"use strict";var e=require("debug"),t=require("postcss-selector-parser"),o=require("fs");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=a(e),n=a(t),s=a(o);const i=r.default("automator:devtool");function c(e){e.walk((e=>{if("tag"===e.type){const t=e.value;e.value="page"===t?"uni-page-body":"uni-"+t}}))}const l=["Page.getElement","Page.getElements","Element.getElement","Element.getElements"];function p(e){try{return require(e)}catch(t){return require(require.resolve(e,{paths:[process.cwd()]}))}}/^win/.test(process.platform);const u=["chromium","firefox","webkit"];let w=!1;try{w=!!p("playwright")}catch(e){}const f=new Map;function h(e="chromium"){const t=e&&u.includes(e)?e:u[0];let o=f.get(t);return o||(o=function(e){if("webkit"===e)return d("webkit");if("firefox"===e)return d("firefox");if(w)return d("chromium");throw new Error("Playwright dependency not found, please install playwright!")}(t),f.set(t,o)),o}function d(e){const t=p("playwright");let o,a;return{type:e,provider:"playwright",async open(r,n,s){o=await t[e].launch(n.options),"firefox"===e&&(n.contextOptions.isMobile=!1),i(`browser.newContext ${JSON.stringify(n.contextOptions)}`);const c=await o.newContext(n.contextOptions);a=await c.newPage(),a.on("console",(e=>{s.emit("App.logAdded",{type:e.type(),args:[e.text()]})})),a.on("pageerror",(e=>{s.emit("App.exceptionThrown",e)})),await a.goto(n.url||r),await a.waitForTimeout(1e3)},close:()=>o.close(),screenshot:(e=!1)=>a.screenshot({fullPage:e}).then((e=>e.toString("base64"))),swipe:e=>new Promise((async t=>{const{startPoint:o,endPoint:r}=e;await a.evaluate((([e,t])=>{window.scrollBy({left:e.x-t.x,top:e.y-t.y,behavior:"smooth"})}),[o,r]),t("swipe success")})),tap:e=>new Promise((async t=>{const{x:o,y:r,duration:n}=e;await a.mouse.move(o,r),await a.mouse.down(),await a.waitForTimeout(n||0),await a.mouse.up(),t("tap success")}))}}let m;const y={"Tool.close":{reflect:async()=>{await m.close()}},"App.exit":{reflect:async()=>{}},"App.enableLog":{reflect:()=>Promise.resolve()},"App.captureScreenshot":{reflect:async(e,t)=>{const o=await m.screenshot(!!t.fullPage);return i(`App.captureScreenshot ${o.length}`),{data:o}}},"App.swipe":{reflect:async(e,t)=>{const o=await m.swipe(t);return i(`App.swipe ${o.length}`),{data:o}}},"App.tap":{reflect:async(e,t)=>{const o=await m.tap(t);return i(`App.tap ${o.length}`),{data:o}}}};!function(e){l.forEach((t=>{e[t]=function(e){return{reflect:async(t,o)=>t(e,o,!1),params:e=>(e.selector&&(e.selector=n.default(c).processSync(e.selector)),e)}}(t)}))}(y);const g={devtools:{name:"browser",paths:[],validate:async function(e){return e.options=e.options||{},e.executablePath&&!e.options.executablePath&&(e.options.executablePath=e.executablePath),e.contextOptions={viewport:Object.assign({width:375,height:667},e.options.defaultViewport||{}),hasTouch:!0,isMobile:!0,deviceScaleFactor:2},e.options.defaultViewport=Object.assign({width:375,height:667,deviceScaleFactor:2,hasTouch:!0,isMobile:!0},e.options.defaultViewport||{}),e.teardown||(e.teardown=!1===e.options.headless?"disconnect":"close"),e},create:async function(e,t,o){t.executablePath?await new Promise(((o,a)=>{const{exec:r}=require("node:child_process");if(/^win/.test(process.platform)){const a="C:\\Users\\Public\\AppData\\Local\\chrome";s.default.existsSync(a)||s.default.mkdirSync(a,{recursive:!0}),r(`start ${t.executablePath} --user-data-dir=${a} ${e}`,(e=>{if(e)throw console.error(`open ${t.executablePath} fail, ${e}`),Error(e)})),setTimeout((()=>{o(null)}),1e3)}else r(`open -a "${t.executablePath}" ${e}`,(e=>{e&&(console.error(`open ${t.executablePath} fail, ${e}`),a(e)),o(null)}))})):(m=h(process.env.BROWSER),i("createDevtools "+(m.provider+" "+m.type+" "+JSON.stringify(t))),await m.open(e,t,o))}},shouldCompile:(e,t)=>!t.url,adapter:y};module.exports=g;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册