brave-real-playwright-core
Version:
Brave-optimized Playwright Core (v1.56.1) with comprehensive stealth patches and error stack sanitization
1,052 lines (1,051 loc) • 26.9 kB
JavaScript
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var cssTokenizer_exports = {};
__export(cssTokenizer_exports, {
AtKeywordToken: () => AtKeywordToken,
BadStringToken: () => BadStringToken,
BadURLToken: () => BadURLToken,
CDCToken: () => CDCToken,
CDOToken: () => CDOToken,
CSSParserToken: () => CSSParserToken,
CloseCurlyToken: () => CloseCurlyToken,
CloseParenToken: () => CloseParenToken,
CloseSquareToken: () => CloseSquareToken,
ColonToken: () => ColonToken,
ColumnToken: () => ColumnToken,
CommaToken: () => CommaToken,
DashMatchToken: () => DashMatchToken,
DelimToken: () => DelimToken,
DimensionToken: () => DimensionToken,
EOFToken: () => EOFToken,
FunctionToken: () => FunctionToken,
GroupingToken: () => GroupingToken,
HashToken: () => HashToken,
IdentToken: () => IdentToken,
IncludeMatchToken: () => IncludeMatchToken,
InvalidCharacterError: () => InvalidCharacterError,
NumberToken: () => NumberToken,
OpenCurlyToken: () => OpenCurlyToken,
OpenParenToken: () => OpenParenToken,
OpenSquareToken: () => OpenSquareToken,
PercentageToken: () => PercentageToken,
PrefixMatchToken: () => PrefixMatchToken,
SemicolonToken: () => SemicolonToken,
StringToken: () => StringToken,
StringValuedToken: () => StringValuedToken,
SubstringMatchToken: () => SubstringMatchToken,
SuffixMatchToken: () => SuffixMatchToken,
URLToken: () => URLToken,
WhitespaceToken: () => WhitespaceToken,
tokenize: () => tokenize
});
module.exports = __toCommonJS(cssTokenizer_exports);
const between = function(num, first, last) {
return num >= first && num <= last;
};
function digit(code) {
return between(code, 48, 57);
}
function hexdigit(code) {
return digit(code) || between(code, 65, 70) || between(code, 97, 102);
}
function uppercaseletter(code) {
return between(code, 65, 90);
}
function lowercaseletter(code) {
return between(code, 97, 122);
}
function letter(code) {
return uppercaseletter(code) || lowercaseletter(code);
}
function nonascii(code) {
return code >= 128;
}
function namestartchar(code) {
return letter(code) || nonascii(code) || code === 95;
}
function namechar(code) {
return namestartchar(code) || digit(code) || code === 45;
}
function nonprintable(code) {
return between(code, 0, 8) || code === 11 || between(code, 14, 31) || code === 127;
}
function newline(code) {
return code === 10;
}
function whitespace(code) {
return newline(code) || code === 9 || code === 32;
}
const maximumallowedcodepoint = 1114111;
class InvalidCharacterError extends Error {
constructor(message) {
super(message);
this.name = "InvalidCharacterError";
}
}
function preprocess(str) {
const codepoints = [];
for (let i = 0; i < str.length; i++) {
let code = str.charCodeAt(i);
if (code === 13 && str.charCodeAt(i + 1) === 10) {
code = 10;
i++;
}
if (code === 13 || code === 12)
code = 10;
if (code === 0)
code = 65533;
if (between(code, 55296, 56319) && between(str.charCodeAt(i + 1), 56320, 57343)) {
const lead = code - 55296;
const trail = str.charCodeAt(i + 1) - 56320;
code = Math.pow(2, 16) + lead * Math.pow(2, 10) + trail;
i++;
}
codepoints.push(code);
}
return codepoints;
}
function stringFromCode(code) {
if (code <= 65535)
return String.fromCharCode(code);
code -= Math.pow(2, 16);
const lead = Math.floor(code / Math.pow(2, 10)) + 55296;
const trail = code % Math.pow(2, 10) + 56320;
return String.fromCharCode(lead) + String.fromCharCode(trail);
}
function tokenize(str1) {
const str = preprocess(str1);
let i = -1;
const tokens = [];
let code;
let line = 0;
let column = 0;
let lastLineLength = 0;
const incrLineno = function() {
line += 1;
lastLineLength = column;
column = 0;
};
const locStart = { line, column };
const codepoint = function(i2) {
if (i2 >= str.length)
return -1;
return str[i2];
};
const next = function(num) {
if (num === void 0)
num = 1;
if (num > 3)
throw "Spec Error: no more than three codepoints of lookahead.";
return codepoint(i + num);
};
const consume = function(num) {
if (num === void 0)
num = 1;
i += num;
code = codepoint(i);
if (newline(code))
incrLineno();
else
column += num;
return true;
};
const reconsume = function() {
i -= 1;
if (newline(code)) {
line -= 1;
column = lastLineLength;
} else {
column -= 1;
}
locStart.line = line;
locStart.column = column;
return true;
};
const eof = function(codepoint2) {
if (codepoint2 === void 0)
codepoint2 = code;
return codepoint2 === -1;
};
const donothing = function() {
};
const parseerror = function() {
};
const consumeAToken = function() {
consumeComments();
consume();
if (whitespace(code)) {
while (whitespace(next()))
consume();
return new WhitespaceToken();
} else if (code === 34) {
return consumeAStringToken();
} else if (code === 35) {
if (namechar(next()) || areAValidEscape(next(1), next(2))) {
const token = new HashToken("");
if (wouldStartAnIdentifier(next(1), next(2), next(3)))
token.type = "id";
token.value = consumeAName();
return token;
} else {
return new DelimToken(code);
}
} else if (code === 36) {
if (next() === 61) {
consume();
return new SuffixMatchToken();
} else {
return new DelimToken(code);
}
} else if (code === 39) {
return consumeAStringToken();
} else if (code === 40) {
return new OpenParenToken();
} else if (code === 41) {
return new CloseParenToken();
} else if (code === 42) {
if (next() === 61) {
consume();
return new SubstringMatchToken();
} else {
return new DelimToken(code);
}
} else if (code === 43) {
if (startsWithANumber()) {
reconsume();
return consumeANumericToken();
} else {
return new DelimToken(code);
}
} else if (code === 44) {
return new CommaToken();
} else if (code === 45) {
if (startsWithANumber()) {
reconsume();
return consumeANumericToken();
} else if (next(1) === 45 && next(2) === 62) {
consume(2);
return new CDCToken();
} else if (startsWithAnIdentifier()) {
reconsume();
return consumeAnIdentlikeToken();
} else {
return new DelimToken(code);
}
} else if (code === 46) {
if (startsWithANumber()) {
reconsume();
return consumeANumericToken();
} else {
return new DelimToken(code);
}
} else if (code === 58) {
return new ColonToken();
} else if (code === 59) {
return new SemicolonToken();
} else if (code === 60) {
if (next(1) === 33 && next(2) === 45 && next(3) === 45) {
consume(3);
return new CDOToken();
} else {
return new DelimToken(code);
}
} else if (code === 64) {
if (wouldStartAnIdentifier(next(1), next(2), next(3)))
return new AtKeywordToken(consumeAName());
else
return new DelimToken(code);
} else if (code === 91) {
return new OpenSquareToken();
} else if (code === 92) {
if (startsWithAValidEscape()) {
reconsume();
return consumeAnIdentlikeToken();
} else {
parseerror();
return new DelimToken(code);
}
} else if (code === 93) {
return new CloseSquareToken();
} else if (code === 94) {
if (next() === 61) {
consume();
return new PrefixMatchToken();
} else {
return new DelimToken(code);
}
} else if (code === 123) {
return new OpenCurlyToken();
} else if (code === 124) {
if (next() === 61) {
consume();
return new DashMatchToken();
} else if (next() === 124) {
consume();
return new ColumnToken();
} else {
return new DelimToken(code);
}
} else if (code === 125) {
return new CloseCurlyToken();
} else if (code === 126) {
if (next() === 61) {
consume();
return new IncludeMatchToken();
} else {
return new DelimToken(code);
}
} else if (digit(code)) {
reconsume();
return consumeANumericToken();
} else if (namestartchar(code)) {
reconsume();
return consumeAnIdentlikeToken();
} else if (eof()) {
return new EOFToken();
} else {
return new DelimToken(code);
}
};
const consumeComments = function() {
while (next(1) === 47 && next(2) === 42) {
consume(2);
while (true) {
consume();
if (code === 42 && next() === 47) {
consume();
break;
} else if (eof()) {
parseerror();
return;
}
}
}
};
const consumeANumericToken = function() {
const num = consumeANumber();
if (wouldStartAnIdentifier(next(1), next(2), next(3))) {
const token = new DimensionToken();
token.value = num.value;
token.repr = num.repr;
token.type = num.type;
token.unit = consumeAName();
return token;
} else if (next() === 37) {
consume();
const token = new PercentageToken();
token.value = num.value;
token.repr = num.repr;
return token;
} else {
const token = new NumberToken();
token.value = num.value;
token.repr = num.repr;
token.type = num.type;
return token;
}
};
const consumeAnIdentlikeToken = function() {
const str2 = consumeAName();
if (str2.toLowerCase() === "url" && next() === 40) {
consume();
while (whitespace(next(1)) && whitespace(next(2)))
consume();
if (next() === 34 || next() === 39)
return new FunctionToken(str2);
else if (whitespace(next()) && (next(2) === 34 || next(2) === 39))
return new FunctionToken(str2);
else
return consumeAURLToken();
} else if (next() === 40) {
consume();
return new FunctionToken(str2);
} else {
return new IdentToken(str2);
}
};
const consumeAStringToken = function(endingCodePoint) {
if (endingCodePoint === void 0)
endingCodePoint = code;
let string = "";
while (consume()) {
if (code === endingCodePoint || eof()) {
return new StringToken(string);
} else if (newline(code)) {
parseerror();
reconsume();
return new BadStringToken();
} else if (code === 92) {
if (eof(next()))
donothing();
else if (newline(next()))
consume();
else
string += stringFromCode(consumeEscape());
} else {
string += stringFromCode(code);
}
}
throw new Error("Internal error");
};
const consumeAURLToken = function() {
const token = new URLToken("");
while (whitespace(next()))
consume();
if (eof(next()))
return token;
while (consume()) {
if (code === 41 || eof()) {
return token;
} else if (whitespace(code)) {
while (whitespace(next()))
consume();
if (next() === 41 || eof(next())) {
consume();
return token;
} else {
consumeTheRemnantsOfABadURL();
return new BadURLToken();
}
} else if (code === 34 || code === 39 || code === 40 || nonprintable(code)) {
parseerror();
consumeTheRemnantsOfABadURL();
return new BadURLToken();
} else if (code === 92) {
if (startsWithAValidEscape()) {
token.value += stringFromCode(consumeEscape());
} else {
parseerror();
consumeTheRemnantsOfABadURL();
return new BadURLToken();
}
} else {
token.value += stringFromCode(code);
}
}
throw new Error("Internal error");
};
const consumeEscape = function() {
consume();
if (hexdigit(code)) {
const digits = [code];
for (let total = 0; total < 5; total++) {
if (hexdigit(next())) {
consume();
digits.push(code);
} else {
break;
}
}
if (whitespace(next()))
consume();
let value = parseInt(digits.map(function(x) {
return String.fromCharCode(x);
}).join(""), 16);
if (value > maximumallowedcodepoint)
value = 65533;
return value;
} else if (eof()) {
return 65533;
} else {
return code;
}
};
const areAValidEscape = function(c1, c2) {
if (c1 !== 92)
return false;
if (newline(c2))
return false;
return true;
};
const startsWithAValidEscape = function() {
return areAValidEscape(code, next());
};
const wouldStartAnIdentifier = function(c1, c2, c3) {
if (c1 === 45)
return namestartchar(c2) || c2 === 45 || areAValidEscape(c2, c3);
else if (namestartchar(c1))
return true;
else if (c1 === 92)
return areAValidEscape(c1, c2);
else
return false;
};
const startsWithAnIdentifier = function() {
return wouldStartAnIdentifier(code, next(1), next(2));
};
const wouldStartANumber = function(c1, c2, c3) {
if (c1 === 43 || c1 === 45) {
if (digit(c2))
return true;
if (c2 === 46 && digit(c3))
return true;
return false;
} else if (c1 === 46) {
if (digit(c2))
return true;
return false;
} else if (digit(c1)) {
return true;
} else {
return false;
}
};
const startsWithANumber = function() {
return wouldStartANumber(code, next(1), next(2));
};
const consumeAName = function() {
let result = "";
while (consume()) {
if (namechar(code)) {
result += stringFromCode(code);
} else if (startsWithAValidEscape()) {
result += stringFromCode(consumeEscape());
} else {
reconsume();
return result;
}
}
throw new Error("Internal parse error");
};
const consumeANumber = function() {
let repr = "";
let type = "integer";
if (next() === 43 || next() === 45) {
consume();
repr += stringFromCode(code);
}
while (digit(next())) {
consume();
repr += stringFromCode(code);
}
if (next(1) === 46 && digit(next(2))) {
consume();
repr += stringFromCode(code);
consume();
repr += stringFromCode(code);
type = "number";
while (digit(next())) {
consume();
repr += stringFromCode(code);
}
}
const c1 = next(1), c2 = next(2), c3 = next(3);
if ((c1 === 69 || c1 === 101) && digit(c2)) {
consume();
repr += stringFromCode(code);
consume();
repr += stringFromCode(code);
type = "number";
while (digit(next())) {
consume();
repr += stringFromCode(code);
}
} else if ((c1 === 69 || c1 === 101) && (c2 === 43 || c2 === 45) && digit(c3)) {
consume();
repr += stringFromCode(code);
consume();
repr += stringFromCode(code);
consume();
repr += stringFromCode(code);
type = "number";
while (digit(next())) {
consume();
repr += stringFromCode(code);
}
}
const value = convertAStringToANumber(repr);
return { type, value, repr };
};
const convertAStringToANumber = function(string) {
return +string;
};
const consumeTheRemnantsOfABadURL = function() {
while (consume()) {
if (code === 41 || eof()) {
return;
} else if (startsWithAValidEscape()) {
consumeEscape();
donothing();
} else {
donothing();
}
}
};
let iterationCount = 0;
while (!eof(next())) {
tokens.push(consumeAToken());
iterationCount++;
if (iterationCount > str.length * 2)
throw new Error("I'm infinite-looping!");
}
return tokens;
}
class CSSParserToken {
constructor() {
this.tokenType = "";
}
toJSON() {
return { token: this.tokenType };
}
toString() {
return this.tokenType;
}
toSource() {
return "" + this;
}
}
class BadStringToken extends CSSParserToken {
constructor() {
super(...arguments);
this.tokenType = "BADSTRING";
}
}
class BadURLToken extends CSSParserToken {
constructor() {
super(...arguments);
this.tokenType = "BADURL";
}
}
class WhitespaceToken extends CSSParserToken {
constructor() {
super(...arguments);
this.tokenType = "WHITESPACE";
}
toString() {
return "WS";
}
toSource() {
return " ";
}
}
class CDOToken extends CSSParserToken {
constructor() {
super(...arguments);
this.tokenType = "CDO";
}
toSource() {
return "<!--";
}
}
class CDCToken extends CSSParserToken {
constructor() {
super(...arguments);
this.tokenType = "CDC";
}
toSource() {
return "-->";
}
}
class ColonToken extends CSSParserToken {
constructor() {
super(...arguments);
this.tokenType = ":";
}
}
class SemicolonToken extends CSSParserToken {
constructor() {
super(...arguments);
this.tokenType = ";";
}
}
class CommaToken extends CSSParserToken {
constructor() {
super(...arguments);
this.tokenType = ",";
}
}
class GroupingToken extends CSSParserToken {
constructor() {
super(...arguments);
this.value = "";
this.mirror = "";
}
}
class OpenCurlyToken extends GroupingToken {
constructor() {
super();
this.tokenType = "{";
this.value = "{";
this.mirror = "}";
}
}
class CloseCurlyToken extends GroupingToken {
constructor() {
super();
this.tokenType = "}";
this.value = "}";
this.mirror = "{";
}
}
class OpenSquareToken extends GroupingToken {
constructor() {
super();
this.tokenType = "[";
this.value = "[";
this.mirror = "]";
}
}
class CloseSquareToken extends GroupingToken {
constructor() {
super();
this.tokenType = "]";
this.value = "]";
this.mirror = "[";
}
}
class OpenParenToken extends GroupingToken {
constructor() {
super();
this.tokenType = "(";
this.value = "(";
this.mirror = ")";
}
}
class CloseParenToken extends GroupingToken {
constructor() {
super();
this.tokenType = ")";
this.value = ")";
this.mirror = "(";
}
}
class IncludeMatchToken extends CSSParserToken {
constructor() {
super(...arguments);
this.tokenType = "~=";
}
}
class DashMatchToken extends CSSParserToken {
constructor() {
super(...arguments);
this.tokenType = "|=";
}
}
class PrefixMatchToken extends CSSParserToken {
constructor() {
super(...arguments);
this.tokenType = "^=";
}
}
class SuffixMatchToken extends CSSParserToken {
constructor() {
super(...arguments);
this.tokenType = "$=";
}
}
class SubstringMatchToken extends CSSParserToken {
constructor() {
super(...arguments);
this.tokenType = "*=";
}
}
class ColumnToken extends CSSParserToken {
constructor() {
super(...arguments);
this.tokenType = "||";
}
}
class EOFToken extends CSSParserToken {
constructor() {
super(...arguments);
this.tokenType = "EOF";
}
toSource() {
return "";
}
}
class DelimToken extends CSSParserToken {
constructor(code) {
super();
this.tokenType = "DELIM";
this.value = "";
this.value = stringFromCode(code);
}
toString() {
return "DELIM(" + this.value + ")";
}
toJSON() {
const json = this.constructor.prototype.constructor.prototype.toJSON.call(this);
json.value = this.value;
return json;
}
toSource() {
if (this.value === "\\")
return "\\\n";
else
return this.value;
}
}
class StringValuedToken extends CSSParserToken {
constructor() {
super(...arguments);
this.value = "";
}
ASCIIMatch(str) {
return this.value.toLowerCase() === str.toLowerCase();
}
toJSON() {
const json = this.constructor.prototype.constructor.prototype.toJSON.call(this);
json.value = this.value;
return json;
}
}
class IdentToken extends StringValuedToken {
constructor(val) {
super();
this.tokenType = "IDENT";
this.value = val;
}
toString() {
return "IDENT(" + this.value + ")";
}
toSource() {
return escapeIdent(this.value);
}
}
class FunctionToken extends StringValuedToken {
constructor(val) {
super();
this.tokenType = "FUNCTION";
this.value = val;
this.mirror = ")";
}
toString() {
return "FUNCTION(" + this.value + ")";
}
toSource() {
return escapeIdent(this.value) + "(";
}
}
class AtKeywordToken extends StringValuedToken {
constructor(val) {
super();
this.tokenType = "AT-KEYWORD";
this.value = val;
}
toString() {
return "AT(" + this.value + ")";
}
toSource() {
return "@" + escapeIdent(this.value);
}
}
class HashToken extends StringValuedToken {
constructor(val) {
super();
this.tokenType = "HASH";
this.value = val;
this.type = "unrestricted";
}
toString() {
return "HASH(" + this.value + ")";
}
toJSON() {
const json = this.constructor.prototype.constructor.prototype.toJSON.call(this);
json.value = this.value;
json.type = this.type;
return json;
}
toSource() {
if (this.type === "id")
return "#" + escapeIdent(this.value);
else
return "#" + escapeHash(this.value);
}
}
class StringToken extends StringValuedToken {
constructor(val) {
super();
this.tokenType = "STRING";
this.value = val;
}
toString() {
return '"' + escapeString(this.value) + '"';
}
}
class URLToken extends StringValuedToken {
constructor(val) {
super();
this.tokenType = "URL";
this.value = val;
}
toString() {
return "URL(" + this.value + ")";
}
toSource() {
return 'url("' + escapeString(this.value) + '")';
}
}
class NumberToken extends CSSParserToken {
constructor() {
super();
this.tokenType = "NUMBER";
this.type = "integer";
this.repr = "";
}
toString() {
if (this.type === "integer")
return "INT(" + this.value + ")";
return "NUMBER(" + this.value + ")";
}
toJSON() {
const json = super.toJSON();
json.value = this.value;
json.type = this.type;
json.repr = this.repr;
return json;
}
toSource() {
return this.repr;
}
}
class PercentageToken extends CSSParserToken {
constructor() {
super();
this.tokenType = "PERCENTAGE";
this.repr = "";
}
toString() {
return "PERCENTAGE(" + this.value + ")";
}
toJSON() {
const json = this.constructor.prototype.constructor.prototype.toJSON.call(this);
json.value = this.value;
json.repr = this.repr;
return json;
}
toSource() {
return this.repr + "%";
}
}
class DimensionToken extends CSSParserToken {
constructor() {
super();
this.tokenType = "DIMENSION";
this.type = "integer";
this.repr = "";
this.unit = "";
}
toString() {
return "DIM(" + this.value + "," + this.unit + ")";
}
toJSON() {
const json = this.constructor.prototype.constructor.prototype.toJSON.call(this);
json.value = this.value;
json.type = this.type;
json.repr = this.repr;
json.unit = this.unit;
return json;
}
toSource() {
const source = this.repr;
let unit = escapeIdent(this.unit);
if (unit[0].toLowerCase() === "e" && (unit[1] === "-" || between(unit.charCodeAt(1), 48, 57))) {
unit = "\\65 " + unit.slice(1, unit.length);
}
return source + unit;
}
}
function escapeIdent(string) {
string = "" + string;
let result = "";
const firstcode = string.charCodeAt(0);
for (let i = 0; i < string.length; i++) {
const code = string.charCodeAt(i);
if (code === 0)
throw new InvalidCharacterError("Invalid character: the input contains U+0000.");
if (between(code, 1, 31) || code === 127 || i === 0 && between(code, 48, 57) || i === 1 && between(code, 48, 57) && firstcode === 45)
result += "\\" + code.toString(16) + " ";
else if (code >= 128 || code === 45 || code === 95 || between(code, 48, 57) || between(code, 65, 90) || between(code, 97, 122))
result += string[i];
else
result += "\\" + string[i];
}
return result;
}
function escapeHash(string) {
string = "" + string;
let result = "";
for (let i = 0; i < string.length; i++) {
const code = string.charCodeAt(i);
if (code === 0)
throw new InvalidCharacterError("Invalid character: the input contains U+0000.");
if (code >= 128 || code === 45 || code === 95 || between(code, 48, 57) || between(code, 65, 90) || between(code, 97, 122))
result += string[i];
else
result += "\\" + code.toString(16) + " ";
}
return result;
}
function escapeString(string) {
string = "" + string;
let result = "";
for (let i = 0; i < string.length; i++) {
const code = string.charCodeAt(i);
if (code === 0)
throw new InvalidCharacterError("Invalid character: the input contains U+0000.");
if (between(code, 1, 31) || code === 127)
result += "\\" + code.toString(16) + " ";
else if (code === 34 || code === 92)
result += "\\" + string[i];
else
result += string[i];
}
return result;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
AtKeywordToken,
BadStringToken,
BadURLToken,
CDCToken,
CDOToken,
CSSParserToken,
CloseCurlyToken,
CloseParenToken,
CloseSquareToken,
ColonToken,
ColumnToken,
CommaToken,
DashMatchToken,
DelimToken,
DimensionToken,
EOFToken,
FunctionToken,
GroupingToken,
HashToken,
IdentToken,
IncludeMatchToken,
InvalidCharacterError,
NumberToken,
OpenCurlyToken,
OpenParenToken,
OpenSquareToken,
PercentageToken,
PrefixMatchToken,
SemicolonToken,
StringToken,
StringValuedToken,
SubstringMatchToken,
SuffixMatchToken,
URLToken,
WhitespaceToken,
tokenize
});