@letsscrapedata/controller 0.0.63 → 0.0.65

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.
Files changed (3) hide show
  1. package/dist/index.cjs +168 -24
  2. package/dist/index.js +168 -24
  3. package/package.json +4 -2
package/dist/index.cjs CHANGED
@@ -403,6 +403,7 @@ var PlaywrightPage = class extends import_node_events.default {
403
403
  #responseInterceptionOptions;
404
404
  #client;
405
405
  #responseCb;
406
+ #isDebugTask;
406
407
  #hasValidUrl(page) {
407
408
  const url = page.url();
408
409
  return url.toLowerCase().startsWith("http");
@@ -672,6 +673,7 @@ var PlaywrightPage = class extends import_node_events.default {
672
673
  this.#responseInterceptionOptions = [];
673
674
  this.#client = null;
674
675
  this.#responseCb = null;
676
+ this.#isDebugTask = false;
675
677
  this.#addPageOn();
676
678
  }
677
679
  async addPreloadScript(scriptOrFunc, arg) {
@@ -793,7 +795,10 @@ var PlaywrightPage = class extends import_node_events.default {
793
795
  if (!this.#page) {
794
796
  throw new Error("No valid page");
795
797
  }
796
- const height = await this.#page.evaluate(() => document.documentElement.scrollHeight);
798
+ let height = await this.#page.evaluate(() => document?.documentElement?.scrollHeight);
799
+ if (typeof height === "undefined") {
800
+ height = 0;
801
+ }
797
802
  return height;
798
803
  }
799
804
  async evaluate(func, args) {
@@ -944,9 +949,18 @@ var PlaywrightPage = class extends import_node_events.default {
944
949
  if (!this.#page) {
945
950
  throw new Error("No valid page");
946
951
  }
947
- const bodyHeight = await this.#page.evaluate(() => document.body.scrollHeight);
948
- const documentHeight = await this.#page.evaluate(() => document.documentElement.scrollHeight);
949
- const windowHeight = await this.#page.evaluate(() => window.outerHeight);
952
+ let bodyHeight = await this.#page.evaluate(() => document?.body?.scrollHeight);
953
+ if (typeof bodyHeight === "undefined") {
954
+ bodyHeight = 0;
955
+ }
956
+ let documentHeight = await this.#page.evaluate(() => document?.documentElement?.scrollHeight);
957
+ if (typeof documentHeight === "undefined") {
958
+ documentHeight = 0;
959
+ }
960
+ let windowHeight = await this.#page.evaluate(() => window.outerHeight);
961
+ if (typeof windowHeight === "undefined") {
962
+ windowHeight = 0;
963
+ }
950
964
  const pageHeight = Math.max(bodyHeight, documentHeight, windowHeight);
951
965
  return pageHeight;
952
966
  }
@@ -960,8 +974,14 @@ var PlaywrightPage = class extends import_node_events.default {
960
974
  if (!this.#page) {
961
975
  throw new Error("No valid page");
962
976
  }
963
- const offsetWidth = await this.#page.evaluate(() => document.documentElement.offsetWidth);
964
- const windowWidth = await this.#page.evaluate(() => window.outerWidth);
977
+ let offsetWidth = await this.#page.evaluate(() => document?.documentElement?.offsetWidth);
978
+ if (typeof offsetWidth === "undefined") {
979
+ offsetWidth = 0;
980
+ }
981
+ let windowWidth = await this.#page.evaluate(() => window.outerWidth);
982
+ if (typeof windowWidth === "undefined") {
983
+ windowWidth = 0;
984
+ }
965
985
  const pageWidth = Math.max(offsetWidth, windowWidth);
966
986
  return pageWidth;
967
987
  }
@@ -1069,6 +1089,8 @@ var PlaywrightPage = class extends import_node_events.default {
1069
1089
  }
1070
1090
  if (typeof taskId === "number") {
1071
1091
  actPageInfo.taskId = taskId;
1092
+ const debug = this.#page && this.#page.pageInfo && this.#page.pageInfo.taskId < 0;
1093
+ this.#isDebugTask = !!debug;
1072
1094
  }
1073
1095
  if (typeof relatedId === "number") {
1074
1096
  actPageInfo.relatedId = relatedId;
@@ -1133,6 +1155,13 @@ var PlaywrightPage = class extends import_node_events.default {
1133
1155
  const { requestMatch, action, fulfill } = option;
1134
1156
  const request = route.request();
1135
1157
  const matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
1158
+ if (this.#isDebugTask) {
1159
+ if (matchedFlag) {
1160
+ logwarn(`##dbg matched request ${request.method()} ${request.url()}`);
1161
+ } else {
1162
+ loginfo(`##dbg unmatched request ${request.method()} ${request.url()}`);
1163
+ }
1164
+ }
1136
1165
  if (matchedFlag) {
1137
1166
  switch (action) {
1138
1167
  case "abort":
@@ -1184,6 +1213,13 @@ var PlaywrightPage = class extends import_node_events.default {
1184
1213
  matchedFlag = false;
1185
1214
  }
1186
1215
  }
1216
+ if (this.#isDebugTask) {
1217
+ if (matchedFlag) {
1218
+ logwarn(`##dbg matched response ${request.method()} ${request.url()}`);
1219
+ } else {
1220
+ loginfo(`##dbg unmatched response ${request.method()} ${request.url()}`);
1221
+ }
1222
+ }
1187
1223
  if (!matchedFlag) {
1188
1224
  continue;
1189
1225
  }
@@ -2212,6 +2248,7 @@ var PuppeteerPage = class extends import_node_events4.default {
2212
2248
  #requestInterceptionNum;
2213
2249
  #responseInterceptionNum;
2214
2250
  #client;
2251
+ #isDebugTask;
2215
2252
  #hasValidUrl(page) {
2216
2253
  const url = page.url();
2217
2254
  return url.toLowerCase().startsWith("http");
@@ -2444,6 +2481,7 @@ var PuppeteerPage = class extends import_node_events4.default {
2444
2481
  this.#requestInterceptionNum = 0;
2445
2482
  this.#responseInterceptionNum = 0;
2446
2483
  this.#client = null;
2484
+ this.#isDebugTask = false;
2447
2485
  this.#addPageOn();
2448
2486
  }
2449
2487
  async addPreloadScript(scriptOrFunc, arg) {
@@ -2562,7 +2600,10 @@ var PuppeteerPage = class extends import_node_events4.default {
2562
2600
  if (!this.#page) {
2563
2601
  throw new Error("No valid page");
2564
2602
  }
2565
- const height = await this.#page.evaluate(() => document.documentElement.scrollHeight);
2603
+ let height = await this.#page.evaluate(() => document?.documentElement?.scrollHeight);
2604
+ if (typeof height === "undefined") {
2605
+ height = 0;
2606
+ }
2566
2607
  return height;
2567
2608
  }
2568
2609
  async evaluate(func, args) {
@@ -2717,9 +2758,18 @@ var PuppeteerPage = class extends import_node_events4.default {
2717
2758
  if (!this.#page) {
2718
2759
  throw new Error("No valid page");
2719
2760
  }
2720
- const bodyHeight = await this.#page.evaluate(() => document.body.scrollHeight);
2721
- const documentHeight = await this.#page.evaluate(() => document.documentElement.scrollHeight);
2722
- const windowHeight = await this.#page.evaluate(() => window.outerHeight);
2761
+ let bodyHeight = await this.#page.evaluate(() => document?.body?.scrollHeight);
2762
+ if (typeof bodyHeight === "undefined") {
2763
+ bodyHeight = 0;
2764
+ }
2765
+ let documentHeight = await this.#page.evaluate(() => document?.documentElement?.scrollHeight);
2766
+ if (typeof documentHeight === "undefined") {
2767
+ documentHeight = 0;
2768
+ }
2769
+ let windowHeight = await this.#page.evaluate(() => window.outerHeight);
2770
+ if (typeof windowHeight === "undefined") {
2771
+ windowHeight = 0;
2772
+ }
2723
2773
  const pageHeight = Math.max(bodyHeight, documentHeight, windowHeight);
2724
2774
  return pageHeight;
2725
2775
  }
@@ -2733,8 +2783,14 @@ var PuppeteerPage = class extends import_node_events4.default {
2733
2783
  if (!this.#page) {
2734
2784
  throw new Error("No valid page");
2735
2785
  }
2736
- const offsetWidth = await this.#page.evaluate(() => document.documentElement.offsetWidth);
2737
- const windowWidth = await this.#page.evaluate(() => window.outerWidth);
2786
+ let offsetWidth = await this.#page.evaluate(() => document?.documentElement?.offsetWidth);
2787
+ if (typeof offsetWidth === "undefined") {
2788
+ offsetWidth = 0;
2789
+ }
2790
+ let windowWidth = await this.#page.evaluate(() => window.outerWidth);
2791
+ if (typeof windowWidth === "undefined") {
2792
+ windowWidth = 0;
2793
+ }
2738
2794
  const pageWidth = Math.max(offsetWidth, windowWidth);
2739
2795
  return pageWidth;
2740
2796
  }
@@ -2841,6 +2897,8 @@ var PuppeteerPage = class extends import_node_events4.default {
2841
2897
  }
2842
2898
  if (typeof taskId === "number") {
2843
2899
  actPageInfo.taskId = taskId;
2900
+ const debug = this.#page && this.#page.pageInfo && this.#page.pageInfo.taskId < 0;
2901
+ this.#isDebugTask = !!debug;
2844
2902
  }
2845
2903
  if (typeof relatedId === "number") {
2846
2904
  actPageInfo.relatedId = relatedId;
@@ -2897,6 +2955,13 @@ var PuppeteerPage = class extends import_node_events4.default {
2897
2955
  for (const option of actOptions) {
2898
2956
  const { requestMatch, action, fulfill } = option;
2899
2957
  const matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
2958
+ if (this.#isDebugTask) {
2959
+ if (matchedFlag) {
2960
+ logwarn(`##dbg matched request ${request.method()} ${request.url()}`);
2961
+ } else {
2962
+ loginfo(`##dbg unmatched request ${request.method()} ${request.url()}`);
2963
+ }
2964
+ }
2900
2965
  if (matchedFlag) {
2901
2966
  switch (action) {
2902
2967
  case "abort":
@@ -2956,6 +3021,13 @@ var PuppeteerPage = class extends import_node_events4.default {
2956
3021
  matchedFlag = false;
2957
3022
  }
2958
3023
  }
3024
+ if (this.#isDebugTask) {
3025
+ if (matchedFlag) {
3026
+ logwarn(`##dbg matched response ${request.method()} ${request.url()}`);
3027
+ } else {
3028
+ loginfo(`##dbg unmatched response ${request.method()} ${request.url()}`);
3029
+ }
3030
+ }
2959
3031
  if (!matchedFlag) {
2960
3032
  continue;
2961
3033
  }
@@ -4326,6 +4398,7 @@ var PatchrightPage = class extends import_node_events8.default {
4326
4398
  #responseInterceptionOptions;
4327
4399
  #client;
4328
4400
  #responseCb;
4401
+ #isDebugTask;
4329
4402
  #hasValidUrl(page) {
4330
4403
  const url = page.url();
4331
4404
  return url.toLowerCase().startsWith("http");
@@ -4595,6 +4668,7 @@ var PatchrightPage = class extends import_node_events8.default {
4595
4668
  this.#responseInterceptionOptions = [];
4596
4669
  this.#client = null;
4597
4670
  this.#responseCb = null;
4671
+ this.#isDebugTask = false;
4598
4672
  this.#addPageOn();
4599
4673
  }
4600
4674
  async addPreloadScript(scriptOrFunc, arg) {
@@ -4716,7 +4790,10 @@ var PatchrightPage = class extends import_node_events8.default {
4716
4790
  if (!this.#page) {
4717
4791
  throw new Error("No valid page");
4718
4792
  }
4719
- const height = await this.#page.evaluate(() => document.documentElement.scrollHeight);
4793
+ let height = await this.#page.evaluate(() => document?.documentElement?.scrollHeight);
4794
+ if (typeof height === "undefined") {
4795
+ height = 0;
4796
+ }
4720
4797
  return height;
4721
4798
  }
4722
4799
  async evaluate(func, args, isolated = true) {
@@ -4866,9 +4943,18 @@ var PatchrightPage = class extends import_node_events8.default {
4866
4943
  if (!this.#page) {
4867
4944
  throw new Error("No valid page");
4868
4945
  }
4869
- const bodyHeight = await this.#page.evaluate(() => document.body.scrollHeight);
4870
- const documentHeight = await this.#page.evaluate(() => document.documentElement.scrollHeight);
4871
- const windowHeight = await this.#page.evaluate(() => window.outerHeight);
4946
+ let bodyHeight = await this.#page.evaluate(() => document?.body?.scrollHeight);
4947
+ if (typeof bodyHeight === "undefined") {
4948
+ bodyHeight = 0;
4949
+ }
4950
+ let documentHeight = await this.#page.evaluate(() => document?.documentElement?.scrollHeight);
4951
+ if (typeof documentHeight === "undefined") {
4952
+ documentHeight = 0;
4953
+ }
4954
+ let windowHeight = await this.#page.evaluate(() => window.outerHeight);
4955
+ if (typeof windowHeight === "undefined") {
4956
+ windowHeight = 0;
4957
+ }
4872
4958
  const pageHeight = Math.max(bodyHeight, documentHeight, windowHeight);
4873
4959
  return pageHeight;
4874
4960
  }
@@ -4882,8 +4968,14 @@ var PatchrightPage = class extends import_node_events8.default {
4882
4968
  if (!this.#page) {
4883
4969
  throw new Error("No valid page");
4884
4970
  }
4885
- const offsetWidth = await this.#page.evaluate(() => document.documentElement.offsetWidth);
4886
- const windowWidth = await this.#page.evaluate(() => window.outerWidth);
4971
+ let offsetWidth = await this.#page.evaluate(() => document?.documentElement?.offsetWidth);
4972
+ if (typeof offsetWidth === "undefined") {
4973
+ offsetWidth = 0;
4974
+ }
4975
+ let windowWidth = await this.#page.evaluate(() => window.outerWidth);
4976
+ if (typeof windowWidth === "undefined") {
4977
+ windowWidth = 0;
4978
+ }
4887
4979
  const pageWidth = Math.max(offsetWidth, windowWidth);
4888
4980
  return pageWidth;
4889
4981
  }
@@ -4991,6 +5083,8 @@ var PatchrightPage = class extends import_node_events8.default {
4991
5083
  }
4992
5084
  if (typeof taskId === "number") {
4993
5085
  actPageInfo.taskId = taskId;
5086
+ const debug = this.#page && this.#page.pageInfo && this.#page.pageInfo.taskId < 0;
5087
+ this.#isDebugTask = !!debug;
4994
5088
  }
4995
5089
  if (typeof relatedId === "number") {
4996
5090
  actPageInfo.relatedId = relatedId;
@@ -5055,6 +5149,13 @@ var PatchrightPage = class extends import_node_events8.default {
5055
5149
  const { requestMatch, action, fulfill } = option;
5056
5150
  const request = route.request();
5057
5151
  const matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
5152
+ if (this.#isDebugTask) {
5153
+ if (matchedFlag) {
5154
+ logwarn(`##dbg matched request ${request.method()} ${request.url()}`);
5155
+ } else {
5156
+ loginfo(`##dbg unmatched request ${request.method()} ${request.url()}`);
5157
+ }
5158
+ }
5058
5159
  if (matchedFlag) {
5059
5160
  switch (action) {
5060
5161
  case "abort":
@@ -5106,6 +5207,13 @@ var PatchrightPage = class extends import_node_events8.default {
5106
5207
  matchedFlag = false;
5107
5208
  }
5108
5209
  }
5210
+ if (this.#isDebugTask) {
5211
+ if (matchedFlag) {
5212
+ logwarn(`##dbg matched response ${request.method()} ${request.url()}`);
5213
+ } else {
5214
+ loginfo(`##dbg unmatched response ${request.method()} ${request.url()}`);
5215
+ }
5216
+ }
5109
5217
  if (!matchedFlag) {
5110
5218
  continue;
5111
5219
  }
@@ -6140,6 +6248,7 @@ var CamoufoxPage = class extends import_node_events11.default {
6140
6248
  #responseInterceptionOptions;
6141
6249
  #client;
6142
6250
  #responseCb;
6251
+ #isDebugTask;
6143
6252
  #hasValidUrl(page) {
6144
6253
  const url = page.url();
6145
6254
  return url.toLowerCase().startsWith("http");
@@ -6409,6 +6518,7 @@ var CamoufoxPage = class extends import_node_events11.default {
6409
6518
  this.#responseInterceptionOptions = [];
6410
6519
  this.#client = null;
6411
6520
  this.#responseCb = null;
6521
+ this.#isDebugTask = false;
6412
6522
  this.#addPageOn();
6413
6523
  }
6414
6524
  async addPreloadScript() {
@@ -6517,7 +6627,10 @@ var CamoufoxPage = class extends import_node_events11.default {
6517
6627
  if (!this.#page) {
6518
6628
  throw new Error("No valid page");
6519
6629
  }
6520
- const height = await this.#page.evaluate(() => document.documentElement.scrollHeight);
6630
+ let height = await this.#page.evaluate(() => document?.documentElement?.scrollHeight);
6631
+ if (typeof height === "undefined") {
6632
+ height = 0;
6633
+ }
6521
6634
  return height;
6522
6635
  }
6523
6636
  async evaluate(func, args, isolated = true) {
@@ -6668,9 +6781,18 @@ var CamoufoxPage = class extends import_node_events11.default {
6668
6781
  if (!this.#page) {
6669
6782
  throw new Error("No valid page");
6670
6783
  }
6671
- const bodyHeight = await this.#page.evaluate(() => document.body.scrollHeight);
6672
- const documentHeight = await this.#page.evaluate(() => document.documentElement.scrollHeight);
6673
- const windowHeight = await this.#page.evaluate(() => window.outerHeight);
6784
+ let bodyHeight = await this.#page.evaluate(() => document?.body?.scrollHeight);
6785
+ if (typeof bodyHeight === "undefined") {
6786
+ bodyHeight = 0;
6787
+ }
6788
+ let documentHeight = await this.#page.evaluate(() => document?.documentElement?.scrollHeight);
6789
+ if (typeof documentHeight === "undefined") {
6790
+ documentHeight = 0;
6791
+ }
6792
+ let windowHeight = await this.#page.evaluate(() => window.outerHeight);
6793
+ if (typeof windowHeight === "undefined") {
6794
+ windowHeight = 0;
6795
+ }
6674
6796
  const pageHeight = Math.max(bodyHeight, documentHeight, windowHeight);
6675
6797
  return pageHeight;
6676
6798
  }
@@ -6684,8 +6806,14 @@ var CamoufoxPage = class extends import_node_events11.default {
6684
6806
  if (!this.#page) {
6685
6807
  throw new Error("No valid page");
6686
6808
  }
6687
- const offsetWidth = await this.#page.evaluate(() => document.documentElement.offsetWidth);
6688
- const windowWidth = await this.#page.evaluate(() => window.outerWidth);
6809
+ let offsetWidth = await this.#page.evaluate(() => document?.documentElement?.offsetWidth);
6810
+ if (typeof offsetWidth === "undefined") {
6811
+ offsetWidth = 0;
6812
+ }
6813
+ let windowWidth = await this.#page.evaluate(() => window.outerWidth);
6814
+ if (typeof windowWidth === "undefined") {
6815
+ windowWidth = 0;
6816
+ }
6689
6817
  const pageWidth = Math.max(offsetWidth, windowWidth);
6690
6818
  return pageWidth;
6691
6819
  }
@@ -6793,6 +6921,8 @@ var CamoufoxPage = class extends import_node_events11.default {
6793
6921
  }
6794
6922
  if (typeof taskId === "number") {
6795
6923
  actPageInfo.taskId = taskId;
6924
+ const debug = this.#page && this.#page.pageInfo && this.#page.pageInfo.taskId < 0;
6925
+ this.#isDebugTask = !!debug;
6796
6926
  }
6797
6927
  if (typeof relatedId === "number") {
6798
6928
  actPageInfo.relatedId = relatedId;
@@ -6857,6 +6987,13 @@ var CamoufoxPage = class extends import_node_events11.default {
6857
6987
  const { requestMatch, action, fulfill } = option;
6858
6988
  const request = route.request();
6859
6989
  const matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
6990
+ if (this.#isDebugTask) {
6991
+ if (matchedFlag) {
6992
+ logwarn(`##dbg matched request ${request.method()} ${request.url()}`);
6993
+ } else {
6994
+ loginfo(`##dbg unmatched request ${request.method()} ${request.url()}`);
6995
+ }
6996
+ }
6860
6997
  if (matchedFlag) {
6861
6998
  switch (action) {
6862
6999
  case "abort":
@@ -6908,6 +7045,13 @@ var CamoufoxPage = class extends import_node_events11.default {
6908
7045
  matchedFlag = false;
6909
7046
  }
6910
7047
  }
7048
+ if (this.#isDebugTask) {
7049
+ if (matchedFlag) {
7050
+ logwarn(`##dbg matched response ${request.method()} ${request.url()}`);
7051
+ } else {
7052
+ loginfo(`##dbg unmatched response ${request.method()} ${request.url()}`);
7053
+ }
7054
+ }
6911
7055
  if (!matchedFlag) {
6912
7056
  continue;
6913
7057
  }
package/dist/index.js CHANGED
@@ -356,6 +356,7 @@ var PlaywrightPage = class extends EventEmitter {
356
356
  #responseInterceptionOptions;
357
357
  #client;
358
358
  #responseCb;
359
+ #isDebugTask;
359
360
  #hasValidUrl(page) {
360
361
  const url = page.url();
361
362
  return url.toLowerCase().startsWith("http");
@@ -625,6 +626,7 @@ var PlaywrightPage = class extends EventEmitter {
625
626
  this.#responseInterceptionOptions = [];
626
627
  this.#client = null;
627
628
  this.#responseCb = null;
629
+ this.#isDebugTask = false;
628
630
  this.#addPageOn();
629
631
  }
630
632
  async addPreloadScript(scriptOrFunc, arg) {
@@ -746,7 +748,10 @@ var PlaywrightPage = class extends EventEmitter {
746
748
  if (!this.#page) {
747
749
  throw new Error("No valid page");
748
750
  }
749
- const height = await this.#page.evaluate(() => document.documentElement.scrollHeight);
751
+ let height = await this.#page.evaluate(() => document?.documentElement?.scrollHeight);
752
+ if (typeof height === "undefined") {
753
+ height = 0;
754
+ }
750
755
  return height;
751
756
  }
752
757
  async evaluate(func, args) {
@@ -897,9 +902,18 @@ var PlaywrightPage = class extends EventEmitter {
897
902
  if (!this.#page) {
898
903
  throw new Error("No valid page");
899
904
  }
900
- const bodyHeight = await this.#page.evaluate(() => document.body.scrollHeight);
901
- const documentHeight = await this.#page.evaluate(() => document.documentElement.scrollHeight);
902
- const windowHeight = await this.#page.evaluate(() => window.outerHeight);
905
+ let bodyHeight = await this.#page.evaluate(() => document?.body?.scrollHeight);
906
+ if (typeof bodyHeight === "undefined") {
907
+ bodyHeight = 0;
908
+ }
909
+ let documentHeight = await this.#page.evaluate(() => document?.documentElement?.scrollHeight);
910
+ if (typeof documentHeight === "undefined") {
911
+ documentHeight = 0;
912
+ }
913
+ let windowHeight = await this.#page.evaluate(() => window.outerHeight);
914
+ if (typeof windowHeight === "undefined") {
915
+ windowHeight = 0;
916
+ }
903
917
  const pageHeight = Math.max(bodyHeight, documentHeight, windowHeight);
904
918
  return pageHeight;
905
919
  }
@@ -913,8 +927,14 @@ var PlaywrightPage = class extends EventEmitter {
913
927
  if (!this.#page) {
914
928
  throw new Error("No valid page");
915
929
  }
916
- const offsetWidth = await this.#page.evaluate(() => document.documentElement.offsetWidth);
917
- const windowWidth = await this.#page.evaluate(() => window.outerWidth);
930
+ let offsetWidth = await this.#page.evaluate(() => document?.documentElement?.offsetWidth);
931
+ if (typeof offsetWidth === "undefined") {
932
+ offsetWidth = 0;
933
+ }
934
+ let windowWidth = await this.#page.evaluate(() => window.outerWidth);
935
+ if (typeof windowWidth === "undefined") {
936
+ windowWidth = 0;
937
+ }
918
938
  const pageWidth = Math.max(offsetWidth, windowWidth);
919
939
  return pageWidth;
920
940
  }
@@ -1022,6 +1042,8 @@ var PlaywrightPage = class extends EventEmitter {
1022
1042
  }
1023
1043
  if (typeof taskId === "number") {
1024
1044
  actPageInfo.taskId = taskId;
1045
+ const debug = this.#page && this.#page.pageInfo && this.#page.pageInfo.taskId < 0;
1046
+ this.#isDebugTask = !!debug;
1025
1047
  }
1026
1048
  if (typeof relatedId === "number") {
1027
1049
  actPageInfo.relatedId = relatedId;
@@ -1086,6 +1108,13 @@ var PlaywrightPage = class extends EventEmitter {
1086
1108
  const { requestMatch, action, fulfill } = option;
1087
1109
  const request = route.request();
1088
1110
  const matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
1111
+ if (this.#isDebugTask) {
1112
+ if (matchedFlag) {
1113
+ logwarn(`##dbg matched request ${request.method()} ${request.url()}`);
1114
+ } else {
1115
+ loginfo(`##dbg unmatched request ${request.method()} ${request.url()}`);
1116
+ }
1117
+ }
1089
1118
  if (matchedFlag) {
1090
1119
  switch (action) {
1091
1120
  case "abort":
@@ -1137,6 +1166,13 @@ var PlaywrightPage = class extends EventEmitter {
1137
1166
  matchedFlag = false;
1138
1167
  }
1139
1168
  }
1169
+ if (this.#isDebugTask) {
1170
+ if (matchedFlag) {
1171
+ logwarn(`##dbg matched response ${request.method()} ${request.url()}`);
1172
+ } else {
1173
+ loginfo(`##dbg unmatched response ${request.method()} ${request.url()}`);
1174
+ }
1175
+ }
1140
1176
  if (!matchedFlag) {
1141
1177
  continue;
1142
1178
  }
@@ -2165,6 +2201,7 @@ var PuppeteerPage = class extends EventEmitter4 {
2165
2201
  #requestInterceptionNum;
2166
2202
  #responseInterceptionNum;
2167
2203
  #client;
2204
+ #isDebugTask;
2168
2205
  #hasValidUrl(page) {
2169
2206
  const url = page.url();
2170
2207
  return url.toLowerCase().startsWith("http");
@@ -2397,6 +2434,7 @@ var PuppeteerPage = class extends EventEmitter4 {
2397
2434
  this.#requestInterceptionNum = 0;
2398
2435
  this.#responseInterceptionNum = 0;
2399
2436
  this.#client = null;
2437
+ this.#isDebugTask = false;
2400
2438
  this.#addPageOn();
2401
2439
  }
2402
2440
  async addPreloadScript(scriptOrFunc, arg) {
@@ -2515,7 +2553,10 @@ var PuppeteerPage = class extends EventEmitter4 {
2515
2553
  if (!this.#page) {
2516
2554
  throw new Error("No valid page");
2517
2555
  }
2518
- const height = await this.#page.evaluate(() => document.documentElement.scrollHeight);
2556
+ let height = await this.#page.evaluate(() => document?.documentElement?.scrollHeight);
2557
+ if (typeof height === "undefined") {
2558
+ height = 0;
2559
+ }
2519
2560
  return height;
2520
2561
  }
2521
2562
  async evaluate(func, args) {
@@ -2670,9 +2711,18 @@ var PuppeteerPage = class extends EventEmitter4 {
2670
2711
  if (!this.#page) {
2671
2712
  throw new Error("No valid page");
2672
2713
  }
2673
- const bodyHeight = await this.#page.evaluate(() => document.body.scrollHeight);
2674
- const documentHeight = await this.#page.evaluate(() => document.documentElement.scrollHeight);
2675
- const windowHeight = await this.#page.evaluate(() => window.outerHeight);
2714
+ let bodyHeight = await this.#page.evaluate(() => document?.body?.scrollHeight);
2715
+ if (typeof bodyHeight === "undefined") {
2716
+ bodyHeight = 0;
2717
+ }
2718
+ let documentHeight = await this.#page.evaluate(() => document?.documentElement?.scrollHeight);
2719
+ if (typeof documentHeight === "undefined") {
2720
+ documentHeight = 0;
2721
+ }
2722
+ let windowHeight = await this.#page.evaluate(() => window.outerHeight);
2723
+ if (typeof windowHeight === "undefined") {
2724
+ windowHeight = 0;
2725
+ }
2676
2726
  const pageHeight = Math.max(bodyHeight, documentHeight, windowHeight);
2677
2727
  return pageHeight;
2678
2728
  }
@@ -2686,8 +2736,14 @@ var PuppeteerPage = class extends EventEmitter4 {
2686
2736
  if (!this.#page) {
2687
2737
  throw new Error("No valid page");
2688
2738
  }
2689
- const offsetWidth = await this.#page.evaluate(() => document.documentElement.offsetWidth);
2690
- const windowWidth = await this.#page.evaluate(() => window.outerWidth);
2739
+ let offsetWidth = await this.#page.evaluate(() => document?.documentElement?.offsetWidth);
2740
+ if (typeof offsetWidth === "undefined") {
2741
+ offsetWidth = 0;
2742
+ }
2743
+ let windowWidth = await this.#page.evaluate(() => window.outerWidth);
2744
+ if (typeof windowWidth === "undefined") {
2745
+ windowWidth = 0;
2746
+ }
2691
2747
  const pageWidth = Math.max(offsetWidth, windowWidth);
2692
2748
  return pageWidth;
2693
2749
  }
@@ -2794,6 +2850,8 @@ var PuppeteerPage = class extends EventEmitter4 {
2794
2850
  }
2795
2851
  if (typeof taskId === "number") {
2796
2852
  actPageInfo.taskId = taskId;
2853
+ const debug = this.#page && this.#page.pageInfo && this.#page.pageInfo.taskId < 0;
2854
+ this.#isDebugTask = !!debug;
2797
2855
  }
2798
2856
  if (typeof relatedId === "number") {
2799
2857
  actPageInfo.relatedId = relatedId;
@@ -2850,6 +2908,13 @@ var PuppeteerPage = class extends EventEmitter4 {
2850
2908
  for (const option of actOptions) {
2851
2909
  const { requestMatch, action, fulfill } = option;
2852
2910
  const matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
2911
+ if (this.#isDebugTask) {
2912
+ if (matchedFlag) {
2913
+ logwarn(`##dbg matched request ${request.method()} ${request.url()}`);
2914
+ } else {
2915
+ loginfo(`##dbg unmatched request ${request.method()} ${request.url()}`);
2916
+ }
2917
+ }
2853
2918
  if (matchedFlag) {
2854
2919
  switch (action) {
2855
2920
  case "abort":
@@ -2909,6 +2974,13 @@ var PuppeteerPage = class extends EventEmitter4 {
2909
2974
  matchedFlag = false;
2910
2975
  }
2911
2976
  }
2977
+ if (this.#isDebugTask) {
2978
+ if (matchedFlag) {
2979
+ logwarn(`##dbg matched response ${request.method()} ${request.url()}`);
2980
+ } else {
2981
+ loginfo(`##dbg unmatched response ${request.method()} ${request.url()}`);
2982
+ }
2983
+ }
2912
2984
  if (!matchedFlag) {
2913
2985
  continue;
2914
2986
  }
@@ -4279,6 +4351,7 @@ var PatchrightPage = class extends EventEmitter8 {
4279
4351
  #responseInterceptionOptions;
4280
4352
  #client;
4281
4353
  #responseCb;
4354
+ #isDebugTask;
4282
4355
  #hasValidUrl(page) {
4283
4356
  const url = page.url();
4284
4357
  return url.toLowerCase().startsWith("http");
@@ -4548,6 +4621,7 @@ var PatchrightPage = class extends EventEmitter8 {
4548
4621
  this.#responseInterceptionOptions = [];
4549
4622
  this.#client = null;
4550
4623
  this.#responseCb = null;
4624
+ this.#isDebugTask = false;
4551
4625
  this.#addPageOn();
4552
4626
  }
4553
4627
  async addPreloadScript(scriptOrFunc, arg) {
@@ -4669,7 +4743,10 @@ var PatchrightPage = class extends EventEmitter8 {
4669
4743
  if (!this.#page) {
4670
4744
  throw new Error("No valid page");
4671
4745
  }
4672
- const height = await this.#page.evaluate(() => document.documentElement.scrollHeight);
4746
+ let height = await this.#page.evaluate(() => document?.documentElement?.scrollHeight);
4747
+ if (typeof height === "undefined") {
4748
+ height = 0;
4749
+ }
4673
4750
  return height;
4674
4751
  }
4675
4752
  async evaluate(func, args, isolated = true) {
@@ -4819,9 +4896,18 @@ var PatchrightPage = class extends EventEmitter8 {
4819
4896
  if (!this.#page) {
4820
4897
  throw new Error("No valid page");
4821
4898
  }
4822
- const bodyHeight = await this.#page.evaluate(() => document.body.scrollHeight);
4823
- const documentHeight = await this.#page.evaluate(() => document.documentElement.scrollHeight);
4824
- const windowHeight = await this.#page.evaluate(() => window.outerHeight);
4899
+ let bodyHeight = await this.#page.evaluate(() => document?.body?.scrollHeight);
4900
+ if (typeof bodyHeight === "undefined") {
4901
+ bodyHeight = 0;
4902
+ }
4903
+ let documentHeight = await this.#page.evaluate(() => document?.documentElement?.scrollHeight);
4904
+ if (typeof documentHeight === "undefined") {
4905
+ documentHeight = 0;
4906
+ }
4907
+ let windowHeight = await this.#page.evaluate(() => window.outerHeight);
4908
+ if (typeof windowHeight === "undefined") {
4909
+ windowHeight = 0;
4910
+ }
4825
4911
  const pageHeight = Math.max(bodyHeight, documentHeight, windowHeight);
4826
4912
  return pageHeight;
4827
4913
  }
@@ -4835,8 +4921,14 @@ var PatchrightPage = class extends EventEmitter8 {
4835
4921
  if (!this.#page) {
4836
4922
  throw new Error("No valid page");
4837
4923
  }
4838
- const offsetWidth = await this.#page.evaluate(() => document.documentElement.offsetWidth);
4839
- const windowWidth = await this.#page.evaluate(() => window.outerWidth);
4924
+ let offsetWidth = await this.#page.evaluate(() => document?.documentElement?.offsetWidth);
4925
+ if (typeof offsetWidth === "undefined") {
4926
+ offsetWidth = 0;
4927
+ }
4928
+ let windowWidth = await this.#page.evaluate(() => window.outerWidth);
4929
+ if (typeof windowWidth === "undefined") {
4930
+ windowWidth = 0;
4931
+ }
4840
4932
  const pageWidth = Math.max(offsetWidth, windowWidth);
4841
4933
  return pageWidth;
4842
4934
  }
@@ -4944,6 +5036,8 @@ var PatchrightPage = class extends EventEmitter8 {
4944
5036
  }
4945
5037
  if (typeof taskId === "number") {
4946
5038
  actPageInfo.taskId = taskId;
5039
+ const debug = this.#page && this.#page.pageInfo && this.#page.pageInfo.taskId < 0;
5040
+ this.#isDebugTask = !!debug;
4947
5041
  }
4948
5042
  if (typeof relatedId === "number") {
4949
5043
  actPageInfo.relatedId = relatedId;
@@ -5008,6 +5102,13 @@ var PatchrightPage = class extends EventEmitter8 {
5008
5102
  const { requestMatch, action, fulfill } = option;
5009
5103
  const request = route.request();
5010
5104
  const matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
5105
+ if (this.#isDebugTask) {
5106
+ if (matchedFlag) {
5107
+ logwarn(`##dbg matched request ${request.method()} ${request.url()}`);
5108
+ } else {
5109
+ loginfo(`##dbg unmatched request ${request.method()} ${request.url()}`);
5110
+ }
5111
+ }
5011
5112
  if (matchedFlag) {
5012
5113
  switch (action) {
5013
5114
  case "abort":
@@ -5059,6 +5160,13 @@ var PatchrightPage = class extends EventEmitter8 {
5059
5160
  matchedFlag = false;
5060
5161
  }
5061
5162
  }
5163
+ if (this.#isDebugTask) {
5164
+ if (matchedFlag) {
5165
+ logwarn(`##dbg matched response ${request.method()} ${request.url()}`);
5166
+ } else {
5167
+ loginfo(`##dbg unmatched response ${request.method()} ${request.url()}`);
5168
+ }
5169
+ }
5062
5170
  if (!matchedFlag) {
5063
5171
  continue;
5064
5172
  }
@@ -6093,6 +6201,7 @@ var CamoufoxPage = class extends EventEmitter11 {
6093
6201
  #responseInterceptionOptions;
6094
6202
  #client;
6095
6203
  #responseCb;
6204
+ #isDebugTask;
6096
6205
  #hasValidUrl(page) {
6097
6206
  const url = page.url();
6098
6207
  return url.toLowerCase().startsWith("http");
@@ -6362,6 +6471,7 @@ var CamoufoxPage = class extends EventEmitter11 {
6362
6471
  this.#responseInterceptionOptions = [];
6363
6472
  this.#client = null;
6364
6473
  this.#responseCb = null;
6474
+ this.#isDebugTask = false;
6365
6475
  this.#addPageOn();
6366
6476
  }
6367
6477
  async addPreloadScript() {
@@ -6470,7 +6580,10 @@ var CamoufoxPage = class extends EventEmitter11 {
6470
6580
  if (!this.#page) {
6471
6581
  throw new Error("No valid page");
6472
6582
  }
6473
- const height = await this.#page.evaluate(() => document.documentElement.scrollHeight);
6583
+ let height = await this.#page.evaluate(() => document?.documentElement?.scrollHeight);
6584
+ if (typeof height === "undefined") {
6585
+ height = 0;
6586
+ }
6474
6587
  return height;
6475
6588
  }
6476
6589
  async evaluate(func, args, isolated = true) {
@@ -6621,9 +6734,18 @@ var CamoufoxPage = class extends EventEmitter11 {
6621
6734
  if (!this.#page) {
6622
6735
  throw new Error("No valid page");
6623
6736
  }
6624
- const bodyHeight = await this.#page.evaluate(() => document.body.scrollHeight);
6625
- const documentHeight = await this.#page.evaluate(() => document.documentElement.scrollHeight);
6626
- const windowHeight = await this.#page.evaluate(() => window.outerHeight);
6737
+ let bodyHeight = await this.#page.evaluate(() => document?.body?.scrollHeight);
6738
+ if (typeof bodyHeight === "undefined") {
6739
+ bodyHeight = 0;
6740
+ }
6741
+ let documentHeight = await this.#page.evaluate(() => document?.documentElement?.scrollHeight);
6742
+ if (typeof documentHeight === "undefined") {
6743
+ documentHeight = 0;
6744
+ }
6745
+ let windowHeight = await this.#page.evaluate(() => window.outerHeight);
6746
+ if (typeof windowHeight === "undefined") {
6747
+ windowHeight = 0;
6748
+ }
6627
6749
  const pageHeight = Math.max(bodyHeight, documentHeight, windowHeight);
6628
6750
  return pageHeight;
6629
6751
  }
@@ -6637,8 +6759,14 @@ var CamoufoxPage = class extends EventEmitter11 {
6637
6759
  if (!this.#page) {
6638
6760
  throw new Error("No valid page");
6639
6761
  }
6640
- const offsetWidth = await this.#page.evaluate(() => document.documentElement.offsetWidth);
6641
- const windowWidth = await this.#page.evaluate(() => window.outerWidth);
6762
+ let offsetWidth = await this.#page.evaluate(() => document?.documentElement?.offsetWidth);
6763
+ if (typeof offsetWidth === "undefined") {
6764
+ offsetWidth = 0;
6765
+ }
6766
+ let windowWidth = await this.#page.evaluate(() => window.outerWidth);
6767
+ if (typeof windowWidth === "undefined") {
6768
+ windowWidth = 0;
6769
+ }
6642
6770
  const pageWidth = Math.max(offsetWidth, windowWidth);
6643
6771
  return pageWidth;
6644
6772
  }
@@ -6746,6 +6874,8 @@ var CamoufoxPage = class extends EventEmitter11 {
6746
6874
  }
6747
6875
  if (typeof taskId === "number") {
6748
6876
  actPageInfo.taskId = taskId;
6877
+ const debug = this.#page && this.#page.pageInfo && this.#page.pageInfo.taskId < 0;
6878
+ this.#isDebugTask = !!debug;
6749
6879
  }
6750
6880
  if (typeof relatedId === "number") {
6751
6881
  actPageInfo.relatedId = relatedId;
@@ -6810,6 +6940,13 @@ var CamoufoxPage = class extends EventEmitter11 {
6810
6940
  const { requestMatch, action, fulfill } = option;
6811
6941
  const request = route.request();
6812
6942
  const matchedFlag = !requestMatch || this.#checkRequestMatch(request, requestMatch);
6943
+ if (this.#isDebugTask) {
6944
+ if (matchedFlag) {
6945
+ logwarn(`##dbg matched request ${request.method()} ${request.url()}`);
6946
+ } else {
6947
+ loginfo(`##dbg unmatched request ${request.method()} ${request.url()}`);
6948
+ }
6949
+ }
6813
6950
  if (matchedFlag) {
6814
6951
  switch (action) {
6815
6952
  case "abort":
@@ -6861,6 +6998,13 @@ var CamoufoxPage = class extends EventEmitter11 {
6861
6998
  matchedFlag = false;
6862
6999
  }
6863
7000
  }
7001
+ if (this.#isDebugTask) {
7002
+ if (matchedFlag) {
7003
+ logwarn(`##dbg matched response ${request.method()} ${request.url()}`);
7004
+ } else {
7005
+ loginfo(`##dbg unmatched response ${request.method()} ${request.url()}`);
7006
+ }
7007
+ }
6864
7008
  if (!matchedFlag) {
6865
7009
  continue;
6866
7010
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letsscrapedata/controller",
3
- "version": "0.0.63",
3
+ "version": "0.0.65",
4
4
  "description": "Unified browser / HTML controller interfaces that support patchright, camoufox, playwright, puppeteer and cheerio",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -38,6 +38,8 @@
38
38
  "controller",
39
39
  "headless",
40
40
  "chrome",
41
+ "patchright",
42
+ "camoufox",
41
43
  "playwright",
42
44
  "puppeteer",
43
45
  "cheerio",
@@ -47,7 +49,7 @@
47
49
  ],
48
50
  "dependencies": {
49
51
  "@letsscrapedata/utils": "^0.0.26",
50
- "camoufox-js-lsd": "^0.6.4",
52
+ "camoufox-js-lsd": "^0.6.5",
51
53
  "cheerio": "^1.0.0",
52
54
  "patchright": "^1.52.5",
53
55
  "playwright": "^1.43.0",