Best JavaScript code snippet using playwright-internal
html-parser.js
Source:html-parser.js
...292 ? options.shouldDecodeNewlinesForHref293 : options.shouldDecodeNewlines294 attrs[i] = {295 name: args[1],296 value: decodeAttr(value, shouldDecodeNewlines)297 }298 }299 // å¦æå¼å§æ ç¾æ¯éä¸å
æ ç¾ï¼åå°è¯¥å¼å§æ ç¾çä¿¡æ¯å
¥æ ï¼å³ push å° stack æ°ç»ä¸ï¼å¹¶å° lastTag çå¼è®¾ç½®ä¸ºè¯¥æ ç¾å300 if (!unary) {301 stack.push({ tag: tagName, lowerCasedTag: tagName.toLowerCase(), attrs: attrs })302 lastTag = tagName303 }304 if (options.start) {305 options.start(tagName, attrs, unary, match.start, match.end)306 }307 }308 // parseEndTag å½æ°ç¨æ¥ parse ç»ææ ç¾309 function parseEndTag (tagName, start, end) {310 let pos, lowerCasedTagName...
crypto.js
Source:crypto.js
1/**2 * General mega crypto port3 */4var range = require('./tools').range;5var randomstring = require('./tools').randomstring;6var sjcl = require('sjcl');7var Aes = sjcl.cipher.aes;8var rsaasm = require('./vendor/rsaasm');9var BigNumber = rsaasm.BigNumber;10var Modulus = rsaasm.Modulus;11// string to array of 32-bit words (big endian)12var s2a = function (b) {13 var a = Array((b.length + 3) >> 2);14 for (var i = 0; i < b.length; i++) {15 a[i >> 2] |= (b.charCodeAt(i) << (24 - (i & 3) * 8));16 }17 return a;18};19// array of 32-bit words to string (big endian)20var a2s = function (a) {21 var b = '';22 for (var i = 0; i < a.length * 4; i++) {23 b = b + String.fromCharCode((a[i >> 2] >>> (24 - (i & 3) * 8)) & 255);24 }25 return b;26};27// convert user-supplied password array28var prepareKey = function (a) {29 var i, j, r, key;30 var aes = [];31 var pkey = [0x93C467E3, 0x7DB0C7A4, 0xD1BE3F81, 0x0152CB56];32 for (j = 0; j < a.length; j += 4) {33 key = [0, 0, 0, 0];34 for (i = 0; i < 4; i++) {35 if (i + j < a.length) {36 key[i] = a[i + j];37 }38 }39 aes.push(new Aes(key));40 }41 for (r = 65536; r--;) {42 for (j = 0; j < aes.length; j++) {43 pkey = aes[j].encrypt(pkey);44 }45 }46 return pkey;47};48var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=';49var b64a = b64.split('');50// substitute standard base64 special characters to prevent JSON escaping, remove padding51var base64urlencode = function (data) {52 var o;53 var h;54 var bits;55 var enc = range(Math.ceil(data.length / 3)).map(function (_s, i) {56 o = Array.apply(null, Array(3)).map(function (_n, x) {57 return data.charCodeAt(x + i * 3);58 });59 bits = o[0] << 16 | o[1] << 8 | o[2];60 h = [(bits >> 18 & 0x3f), (bits >> 12 & 0x3f), (bits >> 6 & 0x3f), (bits & 0x3f)];61 // use hexets to index into b64, and append result to encoded string62 return b64a[h[0]] + b64a[h[1]] + b64a[h[2]] + b64a[h[3]];63 }).join('');64 return (data.length % 3) ? enc.slice(0, (data.length % 3) - 3) : enc;65};66var base64urldecode = function (data) {67 data += '=='.substr((2 - data.length * 3) & 3);68 /* // http://kevin.vanzonneveld.net69 // + original by: Tyler Akins (http://rumkin.com)70 // + improved by: Thunder.m71 // + input by: Aman Gupta72 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)73 // + bugfixed by: Onno Marsman74 // + bugfixed by: Pellentesque Malesuada75 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)76 // + input by: Brett Zamir (http://brett-zamir.me)77 // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)78 // * example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');79 // * returns 1: 'Kevin van Zonneveld'80 // mozilla has this native81 // - but breaks in 2.0.0.12!82 //if (typeof this.window['atob'] === 'function') {83 // return atob(data);84 //} */85 //86 //87 var o1;88 var o2;89 var o3;90 var h1;91 var h2;92 var h3;93 var h4;94 var bits;95 var i = 0;96 var ac = 0;97 var dec = '';98 var tmpArr = [];99 if (!data) {100 return data;101 }102 data += '';103 do { // unpack four hexets into three octets using index points in b64104 h1 = b64.indexOf(data.charAt(i++));105 h2 = b64.indexOf(data.charAt(i++));106 h3 = b64.indexOf(data.charAt(i++));107 h4 = b64.indexOf(data.charAt(i++));108 bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;109 o1 = bits >> 16 & 0xff;110 o2 = bits >> 8 & 0xff;111 o3 = bits & 0xff;112 if (h3 === 64) {113 tmpArr[ac++] = String.fromCharCode(o1);114 } else if (h4 === 64) {115 tmpArr[ac++] = String.fromCharCode(o1, o2);116 } else {117 tmpArr[ac++] = String.fromCharCode(o1, o2, o3);118 }119 } while (i < data.length);120 dec = tmpArr.join('');121 return dec;122};123var stringhash = function (s, aes) {124 var s32 = s2a(s);125 var h32 = [0, 0, 0, 0];126 var i;127 for (i = 0; i < s32.length; i++) {128 h32[i & 3] ^= s32[i];129 }130 for (i = 16384; i--;) {131 h32 = aes.encrypt(h32);132 }133 return a2base64([h32[0], h32[2]]);134};135var a2base64 = function (a) {136 return base64urlencode(a2s(a));137};138var base642a = function (b) {139 return s2a(base64urldecode(b));140};141var encodePrivateKey = function (privk) {142 var plen = privk[3].length * 8;143 var qlen = privk[4].length * 8;144 var dlen = privk[2].length * 8;145 var ulen = privk[7].length * 8;146 var t = String.fromCharCode(qlen / 256) + String.fromCharCode(qlen % 256) + privk[4] +147 String.fromCharCode(plen / 256) + String.fromCharCode(plen % 256) + privk[3] +148 String.fromCharCode(dlen / 256) + String.fromCharCode(dlen % 256) + privk[2] +149 String.fromCharCode(ulen / 256) + String.fromCharCode(ulen % 256) + privk[7];150 while (t.length & 15) t += String.fromCharCode(randomstring(256));151 return t;152};153var decodePrivateKey = function (privk) {154 var privkey = [];155 // decompose private key156 for (var i = 0; i < 4; i++) {157 if (privk.length < 2) {158 break;159 }160 var l = (privk.charCodeAt(0) * 256 + privk.charCodeAt(1) + 7) >> 3;161 if (l > privk.length - 2) {162 break;163 }164 privkey[i] = new BigNumber(privk.substr(2, l));165 privk = privk.substr(l + 2);166 }167 // check format168 if (i !== 4 || privk.length >= 16) {169 return false;170 }171 // restore privkey components via the known ones172 var q = privkey[0];173 var p = privkey[1];174 var d = privkey[2];175 var u = privkey[3];176 var q1 = q.subtract(1);177 var p1 = p.subtract(1);178 var m = new Modulus(p.multiply(q));179 var e = new Modulus(p1.multiply(q1)).inverse(d);180 var dp = d.divide(p1).remainder;181 var dq = d.divide(q1).remainder;182 privkey = [m, e, d, p, q, dp, dq, u];183 for (i = 0; i < privkey.length; i++) {184 privkey[i] = rsaasm.bytes_to_string(privkey[i].toBytes());185 }186 return privkey;187};188var decryptKey = function (cipher, a) {189 if (a.length === 4) {190 return cipher.decrypt(a);191 }192 var x = [];193 for (var i = 0; i < a.length; i += 4) {194 x = x.concat(cipher.decrypt([a[i], a[i + 1], a[i + 2], a[i + 3]]));195 }196 return x;197};198var encryptKey = function (cipher, a) {199 if (!a) {200 a = [];201 }202 if (a.length === 4) {203 return cipher.encrypt(a);204 }205 var x = [];206 for (var i = 0; i < a.length; i += 4) {207 x = x.concat(cipher.encrypt([a[i], a[i + 1], a[i + 2], a[i + 3]]));208 }209 return x;210};211/**212 * Decrypts a ciphertext string with the supplied private key.213 *214 * @param {String} ciphertext215 * Cipher text to decrypt.216 * @param {Array} privkey217 * Private encryption key (in the usual internal format used).218 * @return {String}219 * Decrypted clear text or false in case of an error220 */221// decrypts ciphertext string representing an MPI-formatted big number with the supplied privkey222// returns cleartext string223var RSADecrypt = function (ciphertext, privkey) {224 var l = (ciphertext.charCodeAt(0) * 256 + ciphertext.charCodeAt(1) + 7) >> 3;225 ciphertext = ciphertext.substr(2, l);226 try {227 var cleartext = rsaasm.bytes_to_string(rsaasm.RSA_RAW.decrypt(ciphertext, privkey));228 } catch (err) {229 throw new Error('RSA decryption failed: ' + err);230 }231 if (cleartext.length < privkey[0].length) {232 cleartext = Array(privkey[0].length - cleartext.length + 1).join(String.fromCharCode(0)) + cleartext;233 }234 // Old bogus padding workaround235 if (cleartext.charCodeAt(1) !== 0) {236 cleartext = String.fromCharCode(0) + cleartext;237 }238 return cleartext.substr(2);239};240// array of 32-bit words ArrayBuffer (big endian)241var a32ToAb = function (a) {242 var ab = new Uint8Array(4 * a.length);243 for (var i = 0; i < a.length; i++) {244 ab[4 * i] = a[i] >>> 24;245 ab[4 * i + 1] = a[i] >>> 16 & 255;246 ab[4 * i + 2] = a[i] >>> 8 & 255;247 ab[4 * i + 3] = a[i] & 255;248 }249 return ab;250};251// ArrayBuffer to binary with depadding252var abToStrDepad = function (ab) {253 var b = '';254 var ab8 = new Uint8Array(ab);255 for (var i = 0; i < ab8.length && ab8[i]; i++) {256 b = b + String.fromCharCode(ab8[i]);257 }258 return b;259};260// binary string to ArrayBuffer, 0-padded to AES block size261var str2ab = function (b) {262 var ab = new ArrayBuffer((b.length + 15) & -16);263 var u8 = new Uint8Array(ab);264 for (var i = b.length; i--;) {265 u8[i] = b.charCodeAt(i);266 }267 return ab;268};269var from8 = function (utf8) {270 return decodeURIComponent(escape(utf8));271};272// binary string to ArrayBuffer, 0-padded to AES block size273var base642ab = function (a) {274 return str2ab(base64urldecode(a));275};276// decrypt attributes block using AES-CBC, check for MEGA canary277// attr = ab, key as with enc_attr278// returns [Object] or false279var decodeAttr = function (attr, key) {280 var b;281 attr = rsaasm.AES_CBC.decrypt(attr,282 a32ToAb([key[0] ^ key[4], key[1] ^ key[5], key[2] ^ key[6], key[3] ^ key[7]]), false);283 b = abToStrDepad(attr);284 if (b.substr(0, 6) !== 'MEGA{"') {285 return false;286 }287 try {288 return JSON.parse(from8(b.substr(4)));289 } catch (e) {290 var m = b.match(/"n"\s*:\s*"((?:\\"|.)*?)(\.\w{2,4})?"/);291 var s = m && m[1];292 var l = (s && s.length) || 0;293 var j = ',';294 while (l--) {295 s = s.substr(0, l || 1);296 }297 if (~l) {298 try {299 var name = s + j + 'trunc' + Math.random().toString(16).slice(-4) + (m[2] || '');300 return JSON.parse(from8(b.substr(4).replace(m[0], '"n":"' + name + '"')));301 } catch (e) {}302 }303 return {304 n: 'MALFORMED_ATTRIBUTES'305 };306 }307};308module.exports.s2a = s2a;309module.exports.a2s = a2s;310module.exports.stringhash = stringhash;311module.exports.a2base64 = a2base64;312module.exports.base642a = base642a;313module.exports.prepareKey = prepareKey;314module.exports.base64urlencode = base64urlencode;315module.exports.base64urldecode = base64urldecode;316module.exports.decryptKey = decryptKey;317module.exports.encryptKey = encryptKey;318module.exports.encodePrivateKey = encodePrivateKey;319module.exports.decodePrivateKey = decodePrivateKey;320module.exports.RSADecrypt = RSADecrypt;321module.exports.decodeAttr = decodeAttr;...
parse-html.js
Source:parse-html.js
...38}39const reCache = {}40const encodedAttr = /&(?:lt|gt|quot|amp|#39);/g41const encodedAttrWithNewLines = /&(?:lt|gt|quot|amp|#39|#10|#9);/g42function decodeAttr(value, shouldDecodeNewlines) {43 const re = shouldDecodeNewlines ? encodedAttrWithNewLines : encodedAttr44 return value.replace(re, match => decodingMap[match])45}46const shouldIgnoreFirstNewline = (tag, html) => tag && isIgnoreNewlineTag(tag) && html[0] === '\n'47function parseHTML(html, options = {}) {48 const stack = []49 let lastTag50 let index = 051 while (html) {52 if (!lastTag || !isPlainTextElement(lastTag)) { // æ£å¸¸å
ç´ 53 let textEnd = html.indexOf('<')54 if (textEnd === 0) {55 // 注é56 if (comment.test(html)) {57 const commentEnd = html.indexOf('-->')58 if (commentEnd >= 0) {59 advance(commentEnd + 3)60 continue61 }62 }63 // hack64 if (conditionalComment.test(html)) {65 // const commentEnd = html.indexOf('>')66 if (commentEnd >= 0) {67 advance(commentEnd + 2)68 continue69 }70 }71 // doctype72 let docMatch = html.match(doctype)73 if (docMatch) {74 advance(docMatch[0].length)75 continue76 }77 // ç»ææ ç¾78 let endMatch = html.match(endTag)79 if (endMatch) {80 let curIndex = index81 advance(endMatch[0].length)82 parseEndTag(endMatch[1], curIndex, index)83 continue84 }85 // å¼å§æ ç¾86 let startMatch = parseStartTag()87 if (startMatch) {88 handleStartTag(startMatch)89 if (shouldIgnoreFirstNewline(startMatch.tagName, html)) {90 advance(1)91 }92 continue93 }94 }95 let text, rest, next96 if (textEnd >= 0) {97 rest = html.slice(textEnd)98 while (!startTagOpen.test(rest) && !endTag.test(rest)) {99 next = rest.indexOf('<', 1)100 if (next < 0) break101 textEnd += next102 rest = html.slice(textEnd)103 }104 text = html.substring(0, textEnd)105 }106 if (textEnd < 0) {107 text = html108 }109 if (text) {110 advance(text.length)111 }112 if (options.chars && text) {113 options.chars(text)114 }115 } else { // style script textarea116 const stackedTag = lastTag.toLowerCase()117 const reStackedTag = reCache[stackedTag] || (reCache[stackedTag] = new RegExp(`([\\s\\S]*?)(</${stackedTag}[^>]*>)`, 'i'))118 const rest = html.replace(reStackedTag, function (all, text) {119 if (options.chars) {120 options.chars(text)121 }122 return ''123 })124 index += html.length - rest.length125 html = rest126 parseEndTag(stackedTag)127 }128 }129 parseEndTag()130 function advance(n) {131 index += n132 html = html.substring(n)133 }134 function parseStartTag() {135 const start = html.match(startTagOpen)136 if (start) {137 const match = {138 tagName: start[1],139 attrs: []140 }141 advance(start[0].length)142 let end, attr143 while (!(end = html.match(startTagClose)) && (attr = html.match(attribute))) {144 advance(attr[0].length)145 match.attrs.push(attr)146 }147 if (end) {148 match.unarySlash = end[1] // startTagClose ï¼ï¼ä¸åç»çæè·149 advance(end[0].length)150 return match151 }152 }153 }154 function handleStartTag(match) {155 let { tagName, unarySlash } = match156 const unary = isUnaryTag(tagName) || !!unarySlash157 const l = match.attrs.length158 const attrs = new Array(l)159 for (let i = 0; i < l; i++) {160 const args = match.attrs[i]161 const value = args[3] || args[4] || args[5] || ''162 const shouldDecodeNewline = tagName === 'a' && args[1] === 'href'163 ? shouldDecodeNewlinesForHref164 : shouldDecodeNewlines165 attrs[i] = {166 name: args[1],167 value: decodeAttr(value, shouldDecodeNewline)168 }169 }170 if (!unary) {171 stack.push({ tag: tagName, lowerCasedTag: tagName.toLowerCase(), attrs: attrs, start: match.start, end: match.end })172 lastTag = tagName173 }174 if (options.start) {175 options.start(tagName, attrs, unary)176 }177 }178 function parseEndTag(tagName, start, end) {179 if (!start) start = index180 if (!end) end = index181 let pos, lowerCasedTagName...
parseHTML.flat2.handleStartTag.js
Source:parseHTML.flat2.handleStartTag.js
...70 : options.shouldDecodeNewlines71 // å±æ§å / å±æ§å¼(转ä¹)72 attrs[i] = {73 name: args[1],74 value: decodeAttr(value, shouldDecodeNewlines)75 }76 // ä¿çå±æ§ä½ç½®77 if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {78 attrs[i].start = args.start + args[0].match(/^\s*/).length79 attrs[i].end = args.end80 }81 }82 // æªéåæ ç¾83 if (!unary) {84 stack.push({ tag: tagName, lowerCasedTag: tagName.toLowerCase(), attrs: attrs, start: match.start, end: match.end })85 lastTag = tagName86 }87 // è°ç¨ start é©åå建 AST èç¹88 if (options.start) {...
8337.js
Source:8337.js
...27 }28 var value = args[3] || args[4] || args[5] || "";29 attrs[i] = {30 name: args[1],31 value: decodeAttr(value, options.shouldDecodeNewlines)32 };33 }34 if (!unary) {35 stack.push({36 tag: tagName,37 lowerCasedTag: tagName.toLowerCase(),38 attrs: attrs39 });40 lastTag = tagName;41 }42 if (options.start) {43 options.start(tagName, attrs, unary, match.start, match.end);44 }45}
8908.js
Source:8908.js
...27 }28 var value = args[3] || args[4] || args[5] || "";29 attrs[i] = {30 name: args[1],31 value: decodeAttr(value, options.shouldDecodeNewlines)32 };33 }34 if (!unary) {35 stack.push({36 tag: tagName,37 lowerCasedTag: tagName.toLowerCase(),38 attrs: attrs39 });40 lastTag = tagName;41 }42 if (options.start) {43 options.start(tagName, attrs, unary, match.start, match.end);44 }45}
10959.js
Source:10959.js
...27 }28 var value = args[3] || args[4] || args[5] || "";29 attrs[i] = {30 name: args[1],31 value: decodeAttr(value, options.shouldDecodeNewlines)32 };33 }34 if (!unary) {35 stack.push({36 tag: tagName,37 lowerCasedTag: tagName.toLowerCase(),38 attrs: attrs39 });40 lastTag = tagName;41 }42 if (options.start) {43 options.start(tagName, attrs, unary, match.start, match.end);44 }45}
decodeAttr.js
Source:decodeAttr.js
1const decodingMap = {2 '<': '<',3 '>': '>',4 '"': '"',5 '&': '&',6 ' ': '\n',7 '	': '\t',8 ''': "'"9}10const encodedAttr = /&(?:lt|gt|quot|amp|#39);/g11const encodedAttrWithNewLines = /&(?:lt|gt|quot|amp|#39|#10|#9);/g12/* è¿è¡å±æ§å¼è½¬ä¹ */13function decodeAttr (value, shouldDecodeNewlines) {14 const re = shouldDecodeNewlines ? encodedAttrWithNewLines : encodedAttr15 return value.replace(re, match => decodingMap[match])...
Using AI Code Generation
1const { chromium } = require('playwright');2const { InternalAPI } = require('playwright/internal');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 const input = await page.$('input[name="q"]');7 const value = await page.evaluate(input => input.getAttribute('value'), input);8 const decodedValue = InternalAPI.decodeAttr(value);9 console.log(decodedValue);10 await browser.close();11})();
Using AI Code Generation
1const { decodeAttr } = require('playwright/lib/server/dom.js');2const encodedString = 'data:text/html,%3Cdiv%20id%3D%22test%22%20class%3D%22test%22%20data-test%3D%22test%22%3E%3C%2Fdiv%3E';3const decodedString = decodeAttr(encodedString);4console.log(decodedString);5Thank you for your reply. I have tried the code you have suggested, but it doesn’t work. I have tried to run the code on the command line (node test.js) and in the browser console (node test.js) and both times the output was the same as the input. I have also tried to run the code on the command line with the following command:6but it didn’t work either. I have also tried to import the decodeAttr function in a Playwright test, but it didn’t work either. I have tried to import the decodeAttr function in the following way:7const { decodeAttr } = require('playwright/lib/server/dom.js');8import { decodeAttr } from 'playwright/lib/server/dom.js';9I have also tried to import the decodeAttr function in a Playwright test, but it didn’t work either. I have tried to import the decodeAttr function in the following way:10const { decodeAttr } = require('playwright/lib/server/dom.js');11import { decodeAttr } from 'play
Using AI Code Generation
1const { decodeAttr } = require('playwright/lib/server/supplements/recorder/recorderSupplement');2console.log(decodeAttr('a%20b'));3const { encodeAttr } = require('playwright/lib/server/supplements/recorder/recorderSupplement');4console.log(encodeAttr('a b'));5const { escapeQuotes } = require('playwright/lib/server/supplements/recorder/recorderSupplement');6console.log(escapeQuotes('a"b'));7const { unescapeQuotes } = require('playwright/lib/server/supplements/recorder/recorderSupplement');8console.log(unescapeQuotes('a\"b'));
Using AI Code Generation
1const { decodeAttr } = require('playwright/lib/utils/attributes');2console.log(decodeAttr('&#x27;'));3const { decodeAttr } = require('playwright/lib/utils/attributes');4console.log(decodeAttr('&#x27;'));5const { decodeAttr } = require('playwright/lib/utils/attributes');6console.log(decodeAttr('&#x27;'));7const { decodeAttr } = require('playwright/lib/utils/attributes');8console.log(decodeAttr('&#x27;'));9const { decodeAttr } = require('playwright/lib/utils/attributes');10console.log(decodeAttr('&#x27;'));11const { decodeAttr } = require('playwright/lib/utils/attributes');12console.log(decodeAttr('&#x27;'));13const { decodeAttr } = require('playwright/lib/utils/attributes');14console.log(decodeAttr('&#x27;'));15const { decodeAttr } = require('playwright/lib/utils/attributes');16console.log(decodeAttr('&#x27;'));17const { decodeAttr } = require('playwright/lib/utils/attributes');18console.log(decodeAttr('&#x27;'));19const { decodeAttr } = require('playwright/lib
Using AI Code Generation
1const { decodeAttr } = require('playwright/lib/client/selectorEngine');2const string = 'hello world';3const result = decodeAttr(string);4console.log(result);5const { decodeAttr } = require('playwright/lib/client/selectorEngine');6const string = 'hello world';7const result = decodeAttr(string);8console.log(result);
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!