@skrillex1224/playwright-toolkit 3.0.15 → 3.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.js CHANGED
@@ -34,6 +34,7 @@ var require_constants = __commonJS({
34
34
  "use strict";
35
35
  var WIN_SLASH = "\\\\/";
36
36
  var WIN_NO_SLASH = `[^${WIN_SLASH}]`;
37
+ var DEFAULT_MAX_EXTGLOB_RECURSION = 0;
37
38
  var DOT_LITERAL = "\\.";
38
39
  var PLUS_LITERAL = "\\+";
39
40
  var QMARK_LITERAL = "\\?";
@@ -84,6 +85,7 @@ var require_constants = __commonJS({
84
85
  SEP: "\\"
85
86
  };
86
87
  var POSIX_REGEX_SOURCE = {
88
+ __proto__: null,
87
89
  alnum: "a-zA-Z0-9",
88
90
  alpha: "a-zA-Z",
89
91
  ascii: "\\x00-\\x7F",
@@ -100,6 +102,7 @@ var require_constants = __commonJS({
100
102
  xdigit: "A-Fa-f0-9"
101
103
  };
102
104
  module.exports = {
105
+ DEFAULT_MAX_EXTGLOB_RECURSION,
103
106
  MAX_LENGTH: 1024 * 64,
104
107
  POSIX_REGEX_SOURCE,
105
108
  // regular expressions
@@ -263,19 +266,19 @@ var require_utils = __commonJS({
263
266
  if (input[idx - 1] === "\\") return exports.escapeLast(input, char, idx - 1);
264
267
  return `${input.slice(0, idx)}\\${input.slice(idx)}`;
265
268
  };
266
- exports.removePrefix = (input, state = {}) => {
269
+ exports.removePrefix = (input, state2 = {}) => {
267
270
  let output = input;
268
271
  if (output.startsWith("./")) {
269
272
  output = output.slice(2);
270
- state.prefix = "./";
273
+ state2.prefix = "./";
271
274
  }
272
275
  return output;
273
276
  };
274
- exports.wrapOutput = (input, state = {}, options = {}) => {
277
+ exports.wrapOutput = (input, state2 = {}, options = {}) => {
275
278
  const prepend = options.contains ? "" : "^";
276
279
  const append = options.contains ? "" : "$";
277
280
  let output = `${prepend}(?:${input})${append}`;
278
- if (state.negated === true) {
281
+ if (state2.negated === true) {
279
282
  output = `(?:^(?!${output}).*$)`;
280
283
  }
281
284
  return output;
@@ -561,7 +564,7 @@ var require_scan = __commonJS({
561
564
  base = utils.removeBackslashes(base);
562
565
  }
563
566
  }
564
- const state = {
567
+ const state2 = {
565
568
  prefix,
566
569
  input,
567
570
  start,
@@ -576,11 +579,11 @@ var require_scan = __commonJS({
576
579
  negatedExtglob
577
580
  };
578
581
  if (opts.tokens === true) {
579
- state.maxDepth = 0;
582
+ state2.maxDepth = 0;
580
583
  if (!isPathSeparator(code)) {
581
584
  tokens.push(token);
582
585
  }
583
- state.tokens = tokens;
586
+ state2.tokens = tokens;
584
587
  }
585
588
  if (opts.parts === true || opts.tokens === true) {
586
589
  let prevIndex;
@@ -596,7 +599,7 @@ var require_scan = __commonJS({
596
599
  tokens[idx].value = value;
597
600
  }
598
601
  depth(tokens[idx]);
599
- state.maxDepth += tokens[idx].depth;
602
+ state2.maxDepth += tokens[idx].depth;
600
603
  }
601
604
  if (idx !== 0 || value !== "") {
602
605
  parts.push(value);
@@ -609,13 +612,13 @@ var require_scan = __commonJS({
609
612
  if (opts.tokens) {
610
613
  tokens[tokens.length - 1].value = value;
611
614
  depth(tokens[tokens.length - 1]);
612
- state.maxDepth += tokens[tokens.length - 1].depth;
615
+ state2.maxDepth += tokens[tokens.length - 1].depth;
613
616
  }
614
617
  }
615
- state.slashes = slashes;
616
- state.parts = parts;
618
+ state2.slashes = slashes;
619
+ state2.parts = parts;
617
620
  }
618
- return state;
621
+ return state2;
619
622
  };
620
623
  module.exports = scan;
621
624
  }
@@ -650,6 +653,213 @@ var require_parse = __commonJS({
650
653
  var syntaxError = (type, char) => {
651
654
  return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
652
655
  };
656
+ var splitTopLevel = (input) => {
657
+ const parts = [];
658
+ let bracket = 0;
659
+ let paren = 0;
660
+ let quote = 0;
661
+ let value = "";
662
+ let escaped = false;
663
+ for (const ch of input) {
664
+ if (escaped === true) {
665
+ value += ch;
666
+ escaped = false;
667
+ continue;
668
+ }
669
+ if (ch === "\\") {
670
+ value += ch;
671
+ escaped = true;
672
+ continue;
673
+ }
674
+ if (ch === '"') {
675
+ quote = quote === 1 ? 0 : 1;
676
+ value += ch;
677
+ continue;
678
+ }
679
+ if (quote === 0) {
680
+ if (ch === "[") {
681
+ bracket++;
682
+ } else if (ch === "]" && bracket > 0) {
683
+ bracket--;
684
+ } else if (bracket === 0) {
685
+ if (ch === "(") {
686
+ paren++;
687
+ } else if (ch === ")" && paren > 0) {
688
+ paren--;
689
+ } else if (ch === "|" && paren === 0) {
690
+ parts.push(value);
691
+ value = "";
692
+ continue;
693
+ }
694
+ }
695
+ }
696
+ value += ch;
697
+ }
698
+ parts.push(value);
699
+ return parts;
700
+ };
701
+ var isPlainBranch = (branch) => {
702
+ let escaped = false;
703
+ for (const ch of branch) {
704
+ if (escaped === true) {
705
+ escaped = false;
706
+ continue;
707
+ }
708
+ if (ch === "\\") {
709
+ escaped = true;
710
+ continue;
711
+ }
712
+ if (/[?*+@!()[\]{}]/.test(ch)) {
713
+ return false;
714
+ }
715
+ }
716
+ return true;
717
+ };
718
+ var normalizeSimpleBranch = (branch) => {
719
+ let value = branch.trim();
720
+ let changed = true;
721
+ while (changed === true) {
722
+ changed = false;
723
+ if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
724
+ value = value.slice(2, -1);
725
+ changed = true;
726
+ }
727
+ }
728
+ if (!isPlainBranch(value)) {
729
+ return;
730
+ }
731
+ return value.replace(/\\(.)/g, "$1");
732
+ };
733
+ var hasRepeatedCharPrefixOverlap = (branches) => {
734
+ const values = branches.map(normalizeSimpleBranch).filter(Boolean);
735
+ for (let i = 0; i < values.length; i++) {
736
+ for (let j = i + 1; j < values.length; j++) {
737
+ const a = values[i];
738
+ const b = values[j];
739
+ const char = a[0];
740
+ if (!char || a !== char.repeat(a.length) || b !== char.repeat(b.length)) {
741
+ continue;
742
+ }
743
+ if (a === b || a.startsWith(b) || b.startsWith(a)) {
744
+ return true;
745
+ }
746
+ }
747
+ }
748
+ return false;
749
+ };
750
+ var parseRepeatedExtglob = (pattern, requireEnd = true) => {
751
+ if (pattern[0] !== "+" && pattern[0] !== "*" || pattern[1] !== "(") {
752
+ return;
753
+ }
754
+ let bracket = 0;
755
+ let paren = 0;
756
+ let quote = 0;
757
+ let escaped = false;
758
+ for (let i = 1; i < pattern.length; i++) {
759
+ const ch = pattern[i];
760
+ if (escaped === true) {
761
+ escaped = false;
762
+ continue;
763
+ }
764
+ if (ch === "\\") {
765
+ escaped = true;
766
+ continue;
767
+ }
768
+ if (ch === '"') {
769
+ quote = quote === 1 ? 0 : 1;
770
+ continue;
771
+ }
772
+ if (quote === 1) {
773
+ continue;
774
+ }
775
+ if (ch === "[") {
776
+ bracket++;
777
+ continue;
778
+ }
779
+ if (ch === "]" && bracket > 0) {
780
+ bracket--;
781
+ continue;
782
+ }
783
+ if (bracket > 0) {
784
+ continue;
785
+ }
786
+ if (ch === "(") {
787
+ paren++;
788
+ continue;
789
+ }
790
+ if (ch === ")") {
791
+ paren--;
792
+ if (paren === 0) {
793
+ if (requireEnd === true && i !== pattern.length - 1) {
794
+ return;
795
+ }
796
+ return {
797
+ type: pattern[0],
798
+ body: pattern.slice(2, i),
799
+ end: i
800
+ };
801
+ }
802
+ }
803
+ }
804
+ };
805
+ var getStarExtglobSequenceOutput = (pattern) => {
806
+ let index = 0;
807
+ const chars = [];
808
+ while (index < pattern.length) {
809
+ const match = parseRepeatedExtglob(pattern.slice(index), false);
810
+ if (!match || match.type !== "*") {
811
+ return;
812
+ }
813
+ const branches = splitTopLevel(match.body).map((branch2) => branch2.trim());
814
+ if (branches.length !== 1) {
815
+ return;
816
+ }
817
+ const branch = normalizeSimpleBranch(branches[0]);
818
+ if (!branch || branch.length !== 1) {
819
+ return;
820
+ }
821
+ chars.push(branch);
822
+ index += match.end + 1;
823
+ }
824
+ if (chars.length < 1) {
825
+ return;
826
+ }
827
+ const source = chars.length === 1 ? utils.escapeRegex(chars[0]) : `[${chars.map((ch) => utils.escapeRegex(ch)).join("")}]`;
828
+ return `${source}*`;
829
+ };
830
+ var repeatedExtglobRecursion = (pattern) => {
831
+ let depth = 0;
832
+ let value = pattern.trim();
833
+ let match = parseRepeatedExtglob(value);
834
+ while (match) {
835
+ depth++;
836
+ value = match.body.trim();
837
+ match = parseRepeatedExtglob(value);
838
+ }
839
+ return depth;
840
+ };
841
+ var analyzeRepeatedExtglob = (body, options) => {
842
+ if (options.maxExtglobRecursion === false) {
843
+ return { risky: false };
844
+ }
845
+ const max = typeof options.maxExtglobRecursion === "number" ? options.maxExtglobRecursion : constants.DEFAULT_MAX_EXTGLOB_RECURSION;
846
+ const branches = splitTopLevel(body).map((branch) => branch.trim());
847
+ if (branches.length > 1) {
848
+ if (branches.some((branch) => branch === "") || branches.some((branch) => /^[*?]+$/.test(branch)) || hasRepeatedCharPrefixOverlap(branches)) {
849
+ return { risky: true };
850
+ }
851
+ }
852
+ for (const branch of branches) {
853
+ const safeOutput = getStarExtglobSequenceOutput(branch);
854
+ if (safeOutput) {
855
+ return { risky: true, safeOutput };
856
+ }
857
+ if (repeatedExtglobRecursion(branch) > max) {
858
+ return { risky: true };
859
+ }
860
+ }
861
+ return { risky: false };
862
+ };
653
863
  var parse = (input, options) => {
654
864
  if (typeof input !== "string") {
655
865
  throw new TypeError("Expected a string");
@@ -692,7 +902,7 @@ var require_parse = __commonJS({
692
902
  if (typeof opts.noext === "boolean") {
693
903
  opts.noextglob = opts.noext;
694
904
  }
695
- const state = {
905
+ const state2 = {
696
906
  input,
697
907
  index: -1,
698
908
  start: 0,
@@ -709,57 +919,57 @@ var require_parse = __commonJS({
709
919
  globstar: false,
710
920
  tokens
711
921
  };
712
- input = utils.removePrefix(input, state);
922
+ input = utils.removePrefix(input, state2);
713
923
  len = input.length;
714
924
  const extglobs = [];
715
925
  const braces = [];
716
926
  const stack = [];
717
927
  let prev = bos;
718
928
  let value;
719
- const eos = () => state.index === len - 1;
720
- const peek = state.peek = (n = 1) => input[state.index + n];
721
- const advance = state.advance = () => input[++state.index] || "";
722
- const remaining = () => input.slice(state.index + 1);
929
+ const eos = () => state2.index === len - 1;
930
+ const peek = state2.peek = (n = 1) => input[state2.index + n];
931
+ const advance = state2.advance = () => input[++state2.index] || "";
932
+ const remaining = () => input.slice(state2.index + 1);
723
933
  const consume = (value2 = "", num = 0) => {
724
- state.consumed += value2;
725
- state.index += num;
934
+ state2.consumed += value2;
935
+ state2.index += num;
726
936
  };
727
937
  const append = (token) => {
728
- state.output += token.output != null ? token.output : token.value;
938
+ state2.output += token.output != null ? token.output : token.value;
729
939
  consume(token.value);
730
940
  };
731
941
  const negate = () => {
732
942
  let count = 1;
733
943
  while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
734
944
  advance();
735
- state.start++;
945
+ state2.start++;
736
946
  count++;
737
947
  }
738
948
  if (count % 2 === 0) {
739
949
  return false;
740
950
  }
741
- state.negated = true;
742
- state.start++;
951
+ state2.negated = true;
952
+ state2.start++;
743
953
  return true;
744
954
  };
745
955
  const increment = (type) => {
746
- state[type]++;
956
+ state2[type]++;
747
957
  stack.push(type);
748
958
  };
749
959
  const decrement = (type) => {
750
- state[type]--;
960
+ state2[type]--;
751
961
  stack.pop();
752
962
  };
753
963
  const push = (tok) => {
754
964
  if (prev.type === "globstar") {
755
- const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
965
+ const isBrace = state2.braces > 0 && (tok.type === "comma" || tok.type === "brace");
756
966
  const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
757
967
  if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
758
- state.output = state.output.slice(0, -prev.output.length);
968
+ state2.output = state2.output.slice(0, -prev.output.length);
759
969
  prev.type = "star";
760
970
  prev.value = "*";
761
971
  prev.output = star;
762
- state.output += prev.output;
972
+ state2.output += prev.output;
763
973
  }
764
974
  }
765
975
  if (extglobs.length && tok.type !== "paren") {
@@ -778,15 +988,37 @@ var require_parse = __commonJS({
778
988
  const extglobOpen = (type, value2) => {
779
989
  const token = { ...EXTGLOB_CHARS[value2], conditions: 1, inner: "" };
780
990
  token.prev = prev;
781
- token.parens = state.parens;
782
- token.output = state.output;
991
+ token.parens = state2.parens;
992
+ token.output = state2.output;
993
+ token.startIndex = state2.index;
994
+ token.tokensIndex = tokens.length;
783
995
  const output = (opts.capture ? "(" : "") + token.open;
784
996
  increment("parens");
785
- push({ type, value: value2, output: state.output ? "" : ONE_CHAR });
997
+ push({ type, value: value2, output: state2.output ? "" : ONE_CHAR });
786
998
  push({ type: "paren", extglob: true, value: advance(), output });
787
999
  extglobs.push(token);
788
1000
  };
789
1001
  const extglobClose = (token) => {
1002
+ const literal = input.slice(token.startIndex, state2.index + 1);
1003
+ const body = input.slice(token.startIndex + 2, state2.index);
1004
+ const analysis = analyzeRepeatedExtglob(body, opts);
1005
+ if ((token.type === "plus" || token.type === "star") && analysis.risky) {
1006
+ const safeOutput = analysis.safeOutput ? (token.output ? "" : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput) : void 0;
1007
+ const open = tokens[token.tokensIndex];
1008
+ open.type = "text";
1009
+ open.value = literal;
1010
+ open.output = safeOutput || utils.escapeRegex(literal);
1011
+ for (let i = token.tokensIndex + 1; i < tokens.length; i++) {
1012
+ tokens[i].value = "";
1013
+ tokens[i].output = "";
1014
+ delete tokens[i].suffix;
1015
+ }
1016
+ state2.output = token.output + open.output;
1017
+ state2.backtrack = true;
1018
+ push({ type: "paren", extglob: true, value, output: "" });
1019
+ decrement("parens");
1020
+ return;
1021
+ }
790
1022
  let output = token.close + (opts.capture ? ")" : "");
791
1023
  let rest;
792
1024
  if (token.type === "negate") {
@@ -802,7 +1034,7 @@ var require_parse = __commonJS({
802
1034
  output = token.close = `)${expression})${extglobStar})`;
803
1035
  }
804
1036
  if (token.prev.type === "bos") {
805
- state.negatedExtglob = true;
1037
+ state2.negatedExtglob = true;
806
1038
  }
807
1039
  }
808
1040
  push({ type: "paren", extglob: true, value, output });
@@ -845,11 +1077,11 @@ var require_parse = __commonJS({
845
1077
  }
846
1078
  }
847
1079
  if (output === input && opts.contains === true) {
848
- state.output = input;
849
- return state;
1080
+ state2.output = input;
1081
+ return state2;
850
1082
  }
851
- state.output = utils.wrapOutput(output, state, options);
852
- return state;
1083
+ state2.output = utils.wrapOutput(output, state2, options);
1084
+ return state2;
853
1085
  }
854
1086
  while (!eos()) {
855
1087
  value = advance();
@@ -873,7 +1105,7 @@ var require_parse = __commonJS({
873
1105
  let slashes = 0;
874
1106
  if (match && match[0].length > 2) {
875
1107
  slashes = match[0].length;
876
- state.index += slashes;
1108
+ state2.index += slashes;
877
1109
  if (slashes % 2 !== 0) {
878
1110
  value += "\\";
879
1111
  }
@@ -883,12 +1115,12 @@ var require_parse = __commonJS({
883
1115
  } else {
884
1116
  value += advance();
885
1117
  }
886
- if (state.brackets === 0) {
1118
+ if (state2.brackets === 0) {
887
1119
  push({ type: "text", value });
888
1120
  continue;
889
1121
  }
890
1122
  }
891
- if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
1123
+ if (state2.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
892
1124
  if (opts.posix !== false && value === ":") {
893
1125
  const inner = prev.value.slice(1);
894
1126
  if (inner.includes("[")) {
@@ -900,7 +1132,7 @@ var require_parse = __commonJS({
900
1132
  const posix = POSIX_REGEX_SOURCE[rest2];
901
1133
  if (posix) {
902
1134
  prev.value = pre + posix;
903
- state.backtrack = true;
1135
+ state2.backtrack = true;
904
1136
  advance();
905
1137
  if (!bos.output && tokens.indexOf(prev) === 1) {
906
1138
  bos.output = ONE_CHAR;
@@ -923,14 +1155,14 @@ var require_parse = __commonJS({
923
1155
  append({ value });
924
1156
  continue;
925
1157
  }
926
- if (state.quotes === 1 && value !== '"') {
1158
+ if (state2.quotes === 1 && value !== '"') {
927
1159
  value = utils.escapeRegex(value);
928
1160
  prev.value += value;
929
1161
  append({ value });
930
1162
  continue;
931
1163
  }
932
1164
  if (value === '"') {
933
- state.quotes = state.quotes === 1 ? 0 : 1;
1165
+ state2.quotes = state2.quotes === 1 ? 0 : 1;
934
1166
  if (opts.keepQuotes === true) {
935
1167
  push({ type: "text", value });
936
1168
  }
@@ -942,15 +1174,15 @@ var require_parse = __commonJS({
942
1174
  continue;
943
1175
  }
944
1176
  if (value === ")") {
945
- if (state.parens === 0 && opts.strictBrackets === true) {
1177
+ if (state2.parens === 0 && opts.strictBrackets === true) {
946
1178
  throw new SyntaxError(syntaxError("opening", "("));
947
1179
  }
948
1180
  const extglob = extglobs[extglobs.length - 1];
949
- if (extglob && state.parens === extglob.parens + 1) {
1181
+ if (extglob && state2.parens === extglob.parens + 1) {
950
1182
  extglobClose(extglobs.pop());
951
1183
  continue;
952
1184
  }
953
- push({ type: "paren", value, output: state.parens ? ")" : "\\)" });
1185
+ push({ type: "paren", value, output: state2.parens ? ")" : "\\)" });
954
1186
  decrement("parens");
955
1187
  continue;
956
1188
  }
@@ -971,7 +1203,7 @@ var require_parse = __commonJS({
971
1203
  push({ type: "text", value, output: `\\${value}` });
972
1204
  continue;
973
1205
  }
974
- if (state.brackets === 0) {
1206
+ if (state2.brackets === 0) {
975
1207
  if (opts.strictBrackets === true) {
976
1208
  throw new SyntaxError(syntaxError("opening", "["));
977
1209
  }
@@ -989,14 +1221,14 @@ var require_parse = __commonJS({
989
1221
  continue;
990
1222
  }
991
1223
  const escaped = utils.escapeRegex(prev.value);
992
- state.output = state.output.slice(0, -prev.value.length);
1224
+ state2.output = state2.output.slice(0, -prev.value.length);
993
1225
  if (opts.literalBrackets === true) {
994
- state.output += escaped;
1226
+ state2.output += escaped;
995
1227
  prev.value = escaped;
996
1228
  continue;
997
1229
  }
998
1230
  prev.value = `(${capture}${escaped}|${prev.value})`;
999
- state.output += prev.value;
1231
+ state2.output += prev.value;
1000
1232
  continue;
1001
1233
  }
1002
1234
  if (value === "{" && opts.nobrace !== true) {
@@ -1005,8 +1237,8 @@ var require_parse = __commonJS({
1005
1237
  type: "brace",
1006
1238
  value,
1007
1239
  output: "(",
1008
- outputIndex: state.output.length,
1009
- tokensIndex: state.tokens.length
1240
+ outputIndex: state2.output.length,
1241
+ tokensIndex: state2.tokens.length
1010
1242
  };
1011
1243
  braces.push(open);
1012
1244
  push(open);
@@ -1032,16 +1264,16 @@ var require_parse = __commonJS({
1032
1264
  }
1033
1265
  }
1034
1266
  output = expandRange(range, opts);
1035
- state.backtrack = true;
1267
+ state2.backtrack = true;
1036
1268
  }
1037
1269
  if (brace.comma !== true && brace.dots !== true) {
1038
- const out = state.output.slice(0, brace.outputIndex);
1039
- const toks = state.tokens.slice(brace.tokensIndex);
1270
+ const out = state2.output.slice(0, brace.outputIndex);
1271
+ const toks = state2.tokens.slice(brace.tokensIndex);
1040
1272
  brace.value = brace.output = "\\{";
1041
1273
  value = output = "\\}";
1042
- state.output = out;
1274
+ state2.output = out;
1043
1275
  for (const t of toks) {
1044
- state.output += t.output || t.value;
1276
+ state2.output += t.output || t.value;
1045
1277
  }
1046
1278
  }
1047
1279
  push({ type: "brace", value, output });
@@ -1067,10 +1299,10 @@ var require_parse = __commonJS({
1067
1299
  continue;
1068
1300
  }
1069
1301
  if (value === "/") {
1070
- if (prev.type === "dot" && state.index === state.start + 1) {
1071
- state.start = state.index + 1;
1072
- state.consumed = "";
1073
- state.output = "";
1302
+ if (prev.type === "dot" && state2.index === state2.start + 1) {
1303
+ state2.start = state2.index + 1;
1304
+ state2.consumed = "";
1305
+ state2.output = "";
1074
1306
  tokens.pop();
1075
1307
  prev = bos;
1076
1308
  continue;
@@ -1079,7 +1311,7 @@ var require_parse = __commonJS({
1079
1311
  continue;
1080
1312
  }
1081
1313
  if (value === ".") {
1082
- if (state.braces > 0 && prev.type === "dot") {
1314
+ if (state2.braces > 0 && prev.type === "dot") {
1083
1315
  if (prev.value === ".") prev.output = DOT_LITERAL;
1084
1316
  const brace = braces[braces.length - 1];
1085
1317
  prev.type = "dots";
@@ -1088,7 +1320,7 @@ var require_parse = __commonJS({
1088
1320
  brace.dots = true;
1089
1321
  continue;
1090
1322
  }
1091
- if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
1323
+ if (state2.braces + state2.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
1092
1324
  push({ type: "text", value, output: DOT_LITERAL });
1093
1325
  continue;
1094
1326
  }
@@ -1124,7 +1356,7 @@ var require_parse = __commonJS({
1124
1356
  continue;
1125
1357
  }
1126
1358
  }
1127
- if (opts.nonegate !== true && state.index === 0) {
1359
+ if (opts.nonegate !== true && state2.index === 0) {
1128
1360
  negate();
1129
1361
  continue;
1130
1362
  }
@@ -1138,7 +1370,7 @@ var require_parse = __commonJS({
1138
1370
  push({ type: "plus", value, output: PLUS_LITERAL });
1139
1371
  continue;
1140
1372
  }
1141
- if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
1373
+ if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state2.parens > 0) {
1142
1374
  push({ type: "plus", value });
1143
1375
  continue;
1144
1376
  }
@@ -1160,7 +1392,7 @@ var require_parse = __commonJS({
1160
1392
  const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
1161
1393
  if (match) {
1162
1394
  value += match[0];
1163
- state.index += match[0].length;
1395
+ state2.index += match[0].length;
1164
1396
  }
1165
1397
  push({ type: "text", value });
1166
1398
  continue;
@@ -1170,8 +1402,8 @@ var require_parse = __commonJS({
1170
1402
  prev.star = true;
1171
1403
  prev.value += value;
1172
1404
  prev.output = star;
1173
- state.backtrack = true;
1174
- state.globstar = true;
1405
+ state2.backtrack = true;
1406
+ state2.globstar = true;
1175
1407
  consume(value);
1176
1408
  continue;
1177
1409
  }
@@ -1193,14 +1425,14 @@ var require_parse = __commonJS({
1193
1425
  push({ type: "star", value, output: "" });
1194
1426
  continue;
1195
1427
  }
1196
- const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
1428
+ const isBrace = state2.braces > 0 && (prior.type === "comma" || prior.type === "brace");
1197
1429
  const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
1198
1430
  if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
1199
1431
  push({ type: "star", value, output: "" });
1200
1432
  continue;
1201
1433
  }
1202
1434
  while (rest.slice(0, 3) === "/**") {
1203
- const after = input[state.index + 4];
1435
+ const after = input[state2.index + 4];
1204
1436
  if (after && after !== "/") {
1205
1437
  break;
1206
1438
  }
@@ -1211,31 +1443,31 @@ var require_parse = __commonJS({
1211
1443
  prev.type = "globstar";
1212
1444
  prev.value += value;
1213
1445
  prev.output = globstar(opts);
1214
- state.output = prev.output;
1215
- state.globstar = true;
1446
+ state2.output = prev.output;
1447
+ state2.globstar = true;
1216
1448
  consume(value);
1217
1449
  continue;
1218
1450
  }
1219
1451
  if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
1220
- state.output = state.output.slice(0, -(prior.output + prev.output).length);
1452
+ state2.output = state2.output.slice(0, -(prior.output + prev.output).length);
1221
1453
  prior.output = `(?:${prior.output}`;
1222
1454
  prev.type = "globstar";
1223
1455
  prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
1224
1456
  prev.value += value;
1225
- state.globstar = true;
1226
- state.output += prior.output + prev.output;
1457
+ state2.globstar = true;
1458
+ state2.output += prior.output + prev.output;
1227
1459
  consume(value);
1228
1460
  continue;
1229
1461
  }
1230
1462
  if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
1231
1463
  const end = rest[1] !== void 0 ? "|$" : "";
1232
- state.output = state.output.slice(0, -(prior.output + prev.output).length);
1464
+ state2.output = state2.output.slice(0, -(prior.output + prev.output).length);
1233
1465
  prior.output = `(?:${prior.output}`;
1234
1466
  prev.type = "globstar";
1235
1467
  prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
1236
1468
  prev.value += value;
1237
- state.output += prior.output + prev.output;
1238
- state.globstar = true;
1469
+ state2.output += prior.output + prev.output;
1470
+ state2.globstar = true;
1239
1471
  consume(value + advance());
1240
1472
  push({ type: "slash", value: "/", output: "" });
1241
1473
  continue;
@@ -1244,18 +1476,18 @@ var require_parse = __commonJS({
1244
1476
  prev.type = "globstar";
1245
1477
  prev.value += value;
1246
1478
  prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
1247
- state.output = prev.output;
1248
- state.globstar = true;
1479
+ state2.output = prev.output;
1480
+ state2.globstar = true;
1249
1481
  consume(value + advance());
1250
1482
  push({ type: "slash", value: "/", output: "" });
1251
1483
  continue;
1252
1484
  }
1253
- state.output = state.output.slice(0, -prev.output.length);
1485
+ state2.output = state2.output.slice(0, -prev.output.length);
1254
1486
  prev.type = "globstar";
1255
1487
  prev.output = globstar(opts);
1256
1488
  prev.value += value;
1257
- state.output += prev.output;
1258
- state.globstar = true;
1489
+ state2.output += prev.output;
1490
+ state2.globstar = true;
1259
1491
  consume(value);
1260
1492
  continue;
1261
1493
  }
@@ -1273,52 +1505,52 @@ var require_parse = __commonJS({
1273
1505
  push(token);
1274
1506
  continue;
1275
1507
  }
1276
- if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
1508
+ if (state2.index === state2.start || prev.type === "slash" || prev.type === "dot") {
1277
1509
  if (prev.type === "dot") {
1278
- state.output += NO_DOT_SLASH;
1510
+ state2.output += NO_DOT_SLASH;
1279
1511
  prev.output += NO_DOT_SLASH;
1280
1512
  } else if (opts.dot === true) {
1281
- state.output += NO_DOTS_SLASH;
1513
+ state2.output += NO_DOTS_SLASH;
1282
1514
  prev.output += NO_DOTS_SLASH;
1283
1515
  } else {
1284
- state.output += nodot;
1516
+ state2.output += nodot;
1285
1517
  prev.output += nodot;
1286
1518
  }
1287
1519
  if (peek() !== "*") {
1288
- state.output += ONE_CHAR;
1520
+ state2.output += ONE_CHAR;
1289
1521
  prev.output += ONE_CHAR;
1290
1522
  }
1291
1523
  }
1292
1524
  push(token);
1293
1525
  }
1294
- while (state.brackets > 0) {
1526
+ while (state2.brackets > 0) {
1295
1527
  if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
1296
- state.output = utils.escapeLast(state.output, "[");
1528
+ state2.output = utils.escapeLast(state2.output, "[");
1297
1529
  decrement("brackets");
1298
1530
  }
1299
- while (state.parens > 0) {
1531
+ while (state2.parens > 0) {
1300
1532
  if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", ")"));
1301
- state.output = utils.escapeLast(state.output, "(");
1533
+ state2.output = utils.escapeLast(state2.output, "(");
1302
1534
  decrement("parens");
1303
1535
  }
1304
- while (state.braces > 0) {
1536
+ while (state2.braces > 0) {
1305
1537
  if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "}"));
1306
- state.output = utils.escapeLast(state.output, "{");
1538
+ state2.output = utils.escapeLast(state2.output, "{");
1307
1539
  decrement("braces");
1308
1540
  }
1309
1541
  if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) {
1310
1542
  push({ type: "maybe_slash", value: "", output: `${SLASH_LITERAL}?` });
1311
1543
  }
1312
- if (state.backtrack === true) {
1313
- state.output = "";
1314
- for (const token of state.tokens) {
1315
- state.output += token.output != null ? token.output : token.value;
1544
+ if (state2.backtrack === true) {
1545
+ state2.output = "";
1546
+ for (const token of state2.tokens) {
1547
+ state2.output += token.output != null ? token.output : token.value;
1316
1548
  if (token.suffix) {
1317
- state.output += token.suffix;
1549
+ state2.output += token.suffix;
1318
1550
  }
1319
1551
  }
1320
1552
  }
1321
- return state;
1553
+ return state2;
1322
1554
  };
1323
1555
  parse.fastpaths = (input, options) => {
1324
1556
  const opts = { ...options };
@@ -1342,7 +1574,7 @@ var require_parse = __commonJS({
1342
1574
  const nodot = opts.dot ? NO_DOTS : NO_DOT;
1343
1575
  const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
1344
1576
  const capture = opts.capture ? "" : "?:";
1345
- const state = { negated: false, prefix: "" };
1577
+ const state2 = { negated: false, prefix: "" };
1346
1578
  let star = opts.bash === true ? ".*?" : STAR;
1347
1579
  if (opts.capture) {
1348
1580
  star = `(${star})`;
@@ -1378,7 +1610,7 @@ var require_parse = __commonJS({
1378
1610
  }
1379
1611
  }
1380
1612
  };
1381
- const output = utils.removePrefix(input, state);
1613
+ const output = utils.removePrefix(input, state2);
1382
1614
  let source = create(output);
1383
1615
  if (source && opts.strictSlashes !== true) {
1384
1616
  source += `${SLASH_LITERAL}?`;
@@ -1403,8 +1635,8 @@ var require_picomatch = __commonJS({
1403
1635
  const fns = glob.map((input) => picomatch2(input, options, returnState));
1404
1636
  const arrayMatcher = (str) => {
1405
1637
  for (const isMatch of fns) {
1406
- const state2 = isMatch(str);
1407
- if (state2) return state2;
1638
+ const state3 = isMatch(str);
1639
+ if (state3) return state3;
1408
1640
  }
1409
1641
  return false;
1410
1642
  };
@@ -1417,7 +1649,7 @@ var require_picomatch = __commonJS({
1417
1649
  const opts = options || {};
1418
1650
  const posix = opts.windows;
1419
1651
  const regex = isState ? picomatch2.compileRe(glob, options) : picomatch2.makeRe(glob, options, false, true);
1420
- const state = regex.state;
1652
+ const state2 = regex.state;
1421
1653
  delete regex.state;
1422
1654
  let isIgnored = () => false;
1423
1655
  if (opts.ignore) {
@@ -1426,7 +1658,7 @@ var require_picomatch = __commonJS({
1426
1658
  }
1427
1659
  const matcher = (input, returnObject = false) => {
1428
1660
  const { isMatch, match, output } = picomatch2.test(input, regex, options, { glob, posix });
1429
- const result = { glob, state, regex, posix, input, output, match, isMatch };
1661
+ const result = { glob, state: state2, regex, posix, input, output, match, isMatch };
1430
1662
  if (typeof opts.onResult === "function") {
1431
1663
  opts.onResult(result);
1432
1664
  }
@@ -1447,7 +1679,7 @@ var require_picomatch = __commonJS({
1447
1679
  return returnObject ? result : true;
1448
1680
  };
1449
1681
  if (returnState) {
1450
- matcher.state = state;
1682
+ matcher.state = state2;
1451
1683
  }
1452
1684
  return matcher;
1453
1685
  };
@@ -1485,20 +1717,20 @@ var require_picomatch = __commonJS({
1485
1717
  return parse(pattern, { ...options, fastpaths: false });
1486
1718
  };
1487
1719
  picomatch2.scan = (input, options) => scan(input, options);
1488
- picomatch2.compileRe = (state, options, returnOutput = false, returnState = false) => {
1720
+ picomatch2.compileRe = (state2, options, returnOutput = false, returnState = false) => {
1489
1721
  if (returnOutput === true) {
1490
- return state.output;
1722
+ return state2.output;
1491
1723
  }
1492
1724
  const opts = options || {};
1493
1725
  const prepend = opts.contains ? "" : "^";
1494
1726
  const append = opts.contains ? "" : "$";
1495
- let source = `${prepend}(?:${state.output})${append}`;
1496
- if (state && state.negated === true) {
1727
+ let source = `${prepend}(?:${state2.output})${append}`;
1728
+ if (state2 && state2.negated === true) {
1497
1729
  source = `^(?!${source}).*$`;
1498
1730
  }
1499
1731
  const regex = picomatch2.toRegex(source, options);
1500
1732
  if (returnState === true) {
1501
- regex.state = state;
1733
+ regex.state = state2;
1502
1734
  }
1503
1735
  return regex;
1504
1736
  };
@@ -2512,9 +2744,12 @@ __export(constants_exports, {
2512
2744
  ActorInfo: () => ActorInfo,
2513
2745
  Code: () => Code,
2514
2746
  Device: () => Device,
2747
+ Mode: () => Mode,
2515
2748
  PresetOfLiveViewKey: () => PresetOfLiveViewKey,
2516
2749
  Status: () => Status,
2517
- normalizeDevice: () => normalizeDevice
2750
+ mode: () => mode,
2751
+ normalizeDevice: () => normalizeDevice,
2752
+ normalizeMode: () => normalizeMode
2518
2753
  });
2519
2754
  var Code = {
2520
2755
  Success: 0,
@@ -2534,6 +2769,14 @@ var Device = Object.freeze({
2534
2769
  Desktop: "desktop",
2535
2770
  Mobile: "mobile"
2536
2771
  });
2772
+ var Mode = Object.freeze({
2773
+ Default: "default",
2774
+ Cloak: "cloak"
2775
+ });
2776
+ var mode = Object.freeze({
2777
+ default: Mode.Default,
2778
+ cloak: Mode.Cloak
2779
+ });
2537
2780
  var normalizeDevice = (value, fallback = Device.Desktop) => {
2538
2781
  const normalizedFallback = String(fallback || "").trim().toLowerCase() === Device.Mobile ? Device.Mobile : Device.Desktop;
2539
2782
  const raw = String(value || "").trim().toLowerCase();
@@ -2541,6 +2784,13 @@ var normalizeDevice = (value, fallback = Device.Desktop) => {
2541
2784
  if (raw === Device.Desktop) return Device.Desktop;
2542
2785
  return normalizedFallback;
2543
2786
  };
2787
+ var normalizeMode = (value, fallback = Mode.Default) => {
2788
+ const normalizedFallback = String(fallback || "").trim().toLowerCase() === Mode.Cloak ? Mode.Cloak : Mode.Default;
2789
+ const raw = String(value || "").trim().toLowerCase();
2790
+ if (raw === Mode.Cloak) return Mode.Cloak;
2791
+ if (raw === Mode.Default) return Mode.Default;
2792
+ return normalizedFallback;
2793
+ };
2544
2794
  var createActorInfo = (info) => {
2545
2795
  const normalizeDomain = (value) => {
2546
2796
  if (!value) return "";
@@ -2555,7 +2805,7 @@ var createActorInfo = (info) => {
2555
2805
  const normalizeShare = (value) => {
2556
2806
  const raw = value && typeof value === "object" ? value : {};
2557
2807
  const modeRaw = String(raw.mode || "dom").trim().toLowerCase();
2558
- const mode = ["dom", "response", "custom"].includes(modeRaw) ? modeRaw : "dom";
2808
+ const mode2 = ["dom", "response", "custom"].includes(modeRaw) ? modeRaw : "dom";
2559
2809
  const prefix = String(raw.prefix || "").trim();
2560
2810
  const rawXurl = Array.isArray(raw.xurl) ? raw.xurl : [];
2561
2811
  const normalizeMatcherList = (input) => {
@@ -2600,7 +2850,7 @@ var createActorInfo = (info) => {
2600
2850
  xurl.push(...extraPaths);
2601
2851
  }
2602
2852
  return {
2603
- mode,
2853
+ mode: mode2,
2604
2854
  prefix,
2605
2855
  xurl
2606
2856
  };
@@ -2608,7 +2858,6 @@ var createActorInfo = (info) => {
2608
2858
  const buildLandingUrl = ({ protocol: protocol2, domain: domain2, path: path2 }) => {
2609
2859
  const safeProtocol = String(protocol2).trim();
2610
2860
  const safeDomain = normalizeDomain(domain2);
2611
- if (!safeDomain) return "";
2612
2861
  const safePath = normalizePath(path2);
2613
2862
  return `${safeProtocol}://${safeDomain}${safePath}`;
2614
2863
  };
@@ -2816,18 +3065,6 @@ var ActorInfo = {
2816
3065
  prefix: "",
2817
3066
  xurl: []
2818
3067
  }
2819
- }),
2820
- // 通用网页抓取 Actor:入口 URL 来自 query,因此这里只声明统一的 Actor 元信息。
2821
- webpage: createActorInfo({
2822
- key: "webpage",
2823
- name: "\u901A\u7528\u7F51\u9875",
2824
- domain: "",
2825
- path: "/",
2826
- share: {
2827
- mode: "dom",
2828
- prefix: "",
2829
- xurl: []
2830
- }
2831
3068
  })
2832
3069
  };
2833
3070
 
@@ -3384,8 +3621,8 @@ var normalizeBrowserProfile = (value) => {
3384
3621
  payload: buildBrowserProfilePayload(core, observed)
3385
3622
  };
3386
3623
  };
3387
- var rememberRuntimeState = (state) => {
3388
- rememberedRuntimeState = deepClone(state);
3624
+ var rememberRuntimeState = (state2) => {
3625
+ rememberedRuntimeState = deepClone(state2);
3389
3626
  return rememberedRuntimeState;
3390
3627
  };
3391
3628
  var normalizeRuntimeState = (source = {}, actor = "") => {
@@ -3445,7 +3682,7 @@ var RuntimeEnv = {
3445
3682
  } else {
3446
3683
  delete normalizedRuntime.browser_profile;
3447
3684
  }
3448
- const state = {
3685
+ const state2 = {
3449
3686
  actor: resolvedActor,
3450
3687
  device,
3451
3688
  runtime: normalizedRuntime,
@@ -3459,73 +3696,73 @@ var RuntimeEnv = {
3459
3696
  browserProfileCore: browserProfile.core,
3460
3697
  browserProfileObserved: browserProfile.observed
3461
3698
  };
3462
- rememberRuntimeState(state);
3463
- return state;
3699
+ rememberRuntimeState(state2);
3700
+ return state2;
3464
3701
  },
3465
3702
  // buildEnvPatch 只构造允许回写到后端 env 的字段集合。
3466
3703
  buildEnvPatch(source = {}, actor = "") {
3467
- const state = normalizeRuntimeState(source, actor);
3468
- const browserProfile = buildBrowserProfilePayload(state.browserProfileCore, state.browserProfileObserved);
3704
+ const state2 = normalizeRuntimeState(source, actor);
3705
+ const browserProfile = buildBrowserProfilePayload(state2.browserProfileCore, state2.browserProfileObserved);
3469
3706
  const envPatch = {
3470
- ...Array.isArray(state.cookies) && state.cookies.length > 0 ? { cookies: state.cookies } : {},
3471
- ...Object.keys(state.localStorage || {}).length > 0 ? { local_storage: state.localStorage } : {},
3472
- ...Object.keys(state.sessionStorage || {}).length > 0 ? { session_storage: state.sessionStorage } : {},
3707
+ ...Array.isArray(state2.cookies) && state2.cookies.length > 0 ? { cookies: state2.cookies } : {},
3708
+ ...Object.keys(state2.localStorage || {}).length > 0 ? { local_storage: state2.localStorage } : {},
3709
+ ...Object.keys(state2.sessionStorage || {}).length > 0 ? { session_storage: state2.sessionStorage } : {},
3473
3710
  ...Object.keys(browserProfile).length > 0 ? { browser_profile: browserProfile } : {}
3474
3711
  };
3475
3712
  return Object.keys(envPatch).length > 0 ? envPatch : null;
3476
3713
  },
3477
3714
  // hasLoginState 只判断 runtime 是否存在有效载荷,不再区分具体字段来源。
3478
3715
  hasLoginState(source = {}, actor = "") {
3479
- const state = normalizeRuntimeState(source, actor);
3480
- return isPlainObject(state.runtime) && Object.keys(state.runtime || {}).length > 0;
3716
+ const state2 = normalizeRuntimeState(source, actor);
3717
+ return isPlainObject(state2.runtime) && Object.keys(state2.runtime || {}).length > 0;
3481
3718
  },
3482
3719
  rememberState(source = {}) {
3483
- const state = normalizeRuntimeState(source);
3484
- rememberRuntimeState(state);
3720
+ const state2 = normalizeRuntimeState(source);
3721
+ rememberRuntimeState(state2);
3485
3722
  return RuntimeEnv.peekRememberedState();
3486
3723
  },
3487
3724
  peekRememberedState() {
3488
3725
  return rememberedRuntimeState ? deepClone(rememberedRuntimeState) : null;
3489
3726
  },
3490
3727
  getBrowserProfileCore(source = {}, actor = "") {
3491
- const state = normalizeRuntimeState(source, actor);
3492
- return deepClone(state.browserProfileCore || {});
3728
+ const state2 = normalizeRuntimeState(source, actor);
3729
+ return deepClone(state2.browserProfileCore || {});
3493
3730
  },
3494
3731
  setBrowserProfileCore(source = {}, core = {}, actor = "") {
3495
- const state = normalizeRuntimeState(source, actor);
3732
+ const state2 = normalizeRuntimeState(source, actor);
3496
3733
  const normalizedCore = normalizeBrowserProfileCore({
3497
3734
  ...core,
3498
- device: normalizeKnownDevice(core == null ? void 0 : core.device) || state.device
3735
+ device: normalizeKnownDevice(core == null ? void 0 : core.device) || state2.device
3499
3736
  });
3500
- state.browserProfileCore = normalizedCore;
3501
- state.browserProfile = buildBrowserProfilePayload(normalizedCore, state.browserProfileObserved);
3502
- if (Object.keys(state.browserProfile).length > 0) {
3503
- state.runtime.browser_profile = state.browserProfile;
3737
+ state2.browserProfileCore = normalizedCore;
3738
+ state2.browserProfile = buildBrowserProfilePayload(normalizedCore, state2.browserProfileObserved);
3739
+ if (Object.keys(state2.browserProfile).length > 0) {
3740
+ state2.runtime.browser_profile = state2.browserProfile;
3504
3741
  } else {
3505
- delete state.runtime.browser_profile;
3742
+ delete state2.runtime.browser_profile;
3506
3743
  }
3507
- rememberRuntimeState(state);
3508
- return state;
3744
+ rememberRuntimeState(state2);
3745
+ return state2;
3509
3746
  },
3510
3747
  // applyToPage 只负责把登录态相关字段注入页面:
3511
3748
  // cookies / localStorage / sessionStorage。
3512
3749
  // 指纹、时区、UA、viewport 的回放发生在 launch.js 启动阶段,不在这里做。
3513
3750
  async applyToPage(page, source = {}, options = {}) {
3514
3751
  if (!page) return;
3515
- let state = normalizeRuntimeState(source, (options == null ? void 0 : options.actor) || "");
3752
+ let state2 = normalizeRuntimeState(source, (options == null ? void 0 : options.actor) || "");
3516
3753
  if (typeof (options == null ? void 0 : options.preapply) === "function") {
3517
- state = await options.preapply(state) || state;
3518
- rememberRuntimeState(state);
3754
+ state2 = await options.preapply(state2) || state2;
3755
+ rememberRuntimeState(state2);
3519
3756
  }
3520
3757
  Object.defineProperty(page, PageRuntimeStateKey, {
3521
3758
  configurable: true,
3522
3759
  enumerable: false,
3523
3760
  writable: true,
3524
- value: state
3761
+ value: state2
3525
3762
  });
3526
- const localStorage = state.localStorage || {};
3527
- const sessionStorage = state.sessionStorage || {};
3528
- const cookies = (state.cookies || []).map((cookie) => {
3763
+ const localStorage = state2.localStorage || {};
3764
+ const sessionStorage = state2.sessionStorage || {};
3765
+ const cookies = (state2.cookies || []).map((cookie) => {
3529
3766
  const normalized = { ...cookie };
3530
3767
  if (!normalized.path) {
3531
3768
  normalized.path = "/";
@@ -3563,8 +3800,8 @@ var RuntimeEnv = {
3563
3800
  },
3564
3801
  // captureEnvPatch 在任务结束时采集最新环境快照,用于 pushSuccess / pushFailed 自动回写。
3565
3802
  async captureEnvPatch(page, source = {}, options = {}) {
3566
- const state = normalizeRuntimeState(source, (options == null ? void 0 : options.actor) || "");
3567
- const baseline = RuntimeEnv.buildEnvPatch(state) || {};
3803
+ const state2 = normalizeRuntimeState(source, (options == null ? void 0 : options.actor) || "");
3804
+ const baseline = RuntimeEnv.buildEnvPatch(state2) || {};
3568
3805
  if (!page || typeof page.evaluate !== "function" || typeof page.context !== "function") {
3569
3806
  return Object.keys(baseline).length > 0 ? baseline : null;
3570
3807
  }
@@ -3583,7 +3820,7 @@ var RuntimeEnv = {
3583
3820
  cookies
3584
3821
  },
3585
3822
  {
3586
- browserProfileCore: state.browserProfileCore
3823
+ browserProfileCore: state2.browserProfileCore
3587
3824
  }
3588
3825
  );
3589
3826
  return RuntimeEnv.mergeEnvPatches(baseline, capturedPatch);
@@ -3593,8 +3830,28 @@ var RuntimeEnv = {
3593
3830
  }
3594
3831
  };
3595
3832
 
3833
+ // src/internals/context.js
3834
+ var state = {
3835
+ mode: Mode.Default
3836
+ };
3837
+ var ToolkitContext = {
3838
+ get mode() {
3839
+ return state.mode;
3840
+ },
3841
+ setMode(mode2 = Mode.Default) {
3842
+ state.mode = normalizeMode(mode2, Mode.Default);
3843
+ return state.mode;
3844
+ }
3845
+ };
3846
+ var setToolkitMode = (mode2 = Mode.Default) => ToolkitContext.setMode(mode2);
3847
+
3596
3848
  // entrys/browser.js
3849
+ var ToolkitMode = Object.freeze({
3850
+ default: Mode.Default,
3851
+ cloak: Mode.Cloak
3852
+ });
3597
3853
  var usePlaywrightToolKit = () => {
3854
+ setToolkitMode(Mode.Default);
3598
3855
  return {
3599
3856
  Logger,
3600
3857
  Display,
@@ -3607,6 +3864,7 @@ var usePlaywrightToolKit = () => {
3607
3864
  }
3608
3865
  };
3609
3866
  };
3867
+ usePlaywrightToolKit.Mode = ToolkitMode;
3610
3868
  export {
3611
3869
  usePlaywrightToolKit
3612
3870
  };