From 597c16fb004cc8b0b82f3889c94d26460b89f3b9 Mon Sep 17 00:00:00 2001 From: yihuineng <471110230@qq.com> Date: Tue, 7 Nov 2023 14:54:03 +0800 Subject: [PATCH] chore: remove selenium-atoms --- lib/controllers.js | 44 ++++++++++++++++++++------------------------ package.json | 1 - 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/lib/controllers.js b/lib/controllers.js index f55a2e8..36a3566 100644 --- a/lib/controllers.js +++ b/lib/controllers.js @@ -2,7 +2,6 @@ const fs = require('fs'); const path = require('path'); const assert = require('assert'); const { sync: mkdirp } = require('mkdirp'); -const { getByName: getAtom } = require('selenium-atoms'); const { errors } = require('webdriver-dfn-error-code'); const _ = require('./helper'); @@ -15,23 +14,27 @@ const implicitWaitForCondition = function(func) { return _.waitForCondition(func, this?.implicitWaitMs); }; -const sendJSCommand = async function(atom, args, inDefaultFrame) { - const frames = !inDefaultFrame && this.pageIframe ? [ this.pageIframe ] : []; - const atomScript = getAtom(atom); - let script; - if (frames.length) { - const elem = getAtom('get_element_from_cache'); - const frame = frames[0]; - script = `(function (window) { var document = window.document; - return (${atomScript}); })((${elem.toString('utf8')})(${JSON.stringify(frame)}))`; - } else { - script = `(${atomScript})`; - } - const command = `${script}(${args.map(JSON.stringify).join(',')})`; +const sendJSCommand = async function(script) { + const atomScript = `(function(){return function(){var e=this; +function h(a){var b=typeof a;if("object"==b)if(a){if(a instanceof Array)return"array";if(a instanceof Object)return b;var c=Object.prototype.toString.call(a);if("[object Window]"==c)return"object";if("[object Array]"==c||"number"==typeof a.length&&"undefined"!=typeof a.splice&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("splice"))return"array";if("[object Function]"==c||"undefined"!=typeof a.call&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("call"))return"function"}else return"null";else if("function"== +b&&"undefined"==typeof a.call)return"object";return b}function aa(a){var b=h(a);return"array"==b||"object"==b&&"number"==typeof a.length}function ba(a){var b=typeof a;return"object"==b&&null!=a||"function"==b}var l=Date.now||function(){return+new Date};var ca=window;function m(a,b){this.code=a;this.b=n[a]||p;this.message=b||"";var c=this.b.replace(/((?:^|\\s+)[a-z])/g,function(a){return a.toUpperCase().replace(/^[\\s\xa0]+/g,"")}),d=c.length-5;if(0>d||c.indexOf("Error",d)!=d)c+="Error";this.name=c;c=Error(this.message);c.name=this.name;this.stack=c.stack||""} +(function(){var a=Error;function b(){}b.prototype=a.prototype;m.c=a.prototype;m.prototype=new b;m.prototype.constructor=m;m.b=function(b,d,g){for(var f=Array(arguments.length-2),k=2;kb?1:0};function x(a,b){for(var c=a.length,d=Array(c),g="string"==typeof a?a.split(""):a,f=0;fparseFloat(a))?String(b):a}(),M={},ka=e.document,la=ka&&J?ja()||("CSS1Compat"==ka.compatMode?parseInt(L,10):5):void 0;var ma=B("Firefox"),na=G()||B("iPod"),oa=B("iPad"),N=B("Android")&&!(F()||B("Firefox")||E()||B("Silk")),pa=F(),qa=B("Safari")&&!(F()||B("Coast")||E()||B("Edge")||B("Silk")||B("Android"))&&!(G()||B("iPad")||B("iPod"));function O(a){return(a=a.exec(y))?a[1]:""}var ra=function(){if(ma)return O(/Firefox\\/([0-9.]+)/);if(J||ga||fa)return L;if(pa)return O(/Chrome\\/([0-9.]+)/);if(qa&&!(G()||B("iPad")||B("iPod")))return O(/Version\\/([0-9.]+)/);if(na||oa){var a;if(a=/Version\\/(\\S+).*Mobile\\/(\\S+)/.exec(y))return a[1]+"."+a[2]}else if(N)return(a=O(/Android\\s+([0-9.]+)/))?a:O(/Version\\/([0-9.]+)/);return""}();var P,ta;function Q(a){R?ta(a):N?r(ua,a):r(ra,a)}var R=function(){if(!K)return!1;var a=e.Components;if(!a)return!1;try{if(!a.classes)return!1}catch(b){return!1}var c=a.classes,a=a.interfaces,d=c["@mozilla.org/xpcom/version-comparator;1"].getService(a.nsIVersionComparator),c=c["@mozilla.org/xre/app-info;1"].getService(a.nsIXULAppInfo),g=c.platformVersion,f=c.version;P=function(a){return 0<=d.compare(g,""+a)};ta=function(a){d.compare(f,""+a)};return!0}(),S; +if(N){var va=/Android\\s+([0-9\\.]+)/.exec(y);S=va?va[1]:"0"}else S="0";var ua=S;N&&Q(2.3);N&&Q(4);qa&&Q(6);function wa(){} +function T(a,b,c){if(null==b)c.push("null");else{if("object"==typeof b){if("array"==h(b)){var d=b;b=d.length;c.push("[");for(var g="",f=0;f { - res = await this.page.evaluate(command); + res = await (this.pageIframe || this.page).evaluate(command); return !!res; }); @@ -305,18 +308,11 @@ controllers.title = async function() { * * @module execute * @param script script - * @param [args] script argument array * @return {Promise.} */ -controllers.execute = async function(script, args) { - if (!args) { - args = []; - } +controllers.execute = async function(script) { - const value = await sendJSCommand.call(this, 'execute_script', [ - script, - args, - ], true); + const value = await sendJSCommand.call(this, script); if (Array.isArray(value)) { return value.map(convertAtoms2Element.bind(this)); diff --git a/package.json b/package.json index 8f3f0b0..aa86554 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "lodash": "^4.17.21", "mkdirp": "^1.0.4", "playwright": "^1.38.0", - "selenium-atoms": "^1.0.4", "webdriver-dfn-error-code": "^1.0.4", "xlogger": "^1.0.6" },