5
5
rewriteDASH ,
6
6
rewriteHLS ,
7
7
removeRangeAsQuery ,
8
+ DISABLE_MEDIASOURCE_SCRIPT ,
8
9
} from "@webrecorder/wabac" ;
9
10
10
11
import { Buffer } from "buffer" ;
@@ -60,6 +61,7 @@ class Recorder {
60
61
archiveFlash = false ;
61
62
archiveScreenshots = false ;
62
63
archivePDF = false ;
64
+ disableMSE = false ;
63
65
64
66
_fetchQueue : FetchEntry [ ] = [ ] ;
65
67
@@ -160,8 +162,10 @@ class Recorder {
160
162
this . archiveCookies = ( await getLocalOption ( "archiveCookies" ) ) === "1" ;
161
163
this . archiveStorage = ( await getLocalOption ( "archiveStorage" ) ) === "1" ;
162
164
this . archiveFlash = ( await getLocalOption ( "archiveFlash" ) ) === "1" ;
163
- this . archiveScreenshots = ( await getLocalOption ( "archiveScreenshots" ) ) === "1" ;
165
+ this . archiveScreenshots =
166
+ ( await getLocalOption ( "archiveScreenshots" ) ) === "1" ;
164
167
this . archivePDF = ( await getLocalOption ( "archivePDF" ) ) === "1" ;
168
+ this . disableMSE = ( await getLocalOption ( "disableMSE" ) ) === "1" ;
165
169
}
166
170
167
171
// @ts -expect-error - TS7006 - Parameter 'autorun' implicitly has an 'any' type.
@@ -196,7 +200,8 @@ class Recorder {
196
200
} );
197
201
198
202
window.addEventListener("beforeunload", () => {});\n` +
199
- ( this . archiveFlash ? this . getFlashInjectScript ( ) : "" )
203
+ ( this . archiveFlash ? this . getFlashInjectScript ( ) : "" ) +
204
+ ( this . disableMSE ? DISABLE_MEDIASOURCE_SCRIPT : "" )
200
205
) ;
201
206
}
202
207
@@ -937,13 +942,13 @@ class Recorder {
937
942
// eslint-disable-next-line @typescript-eslint/no-explicit-any
938
943
async savePDF ( pageInfo : any ) {
939
944
// @ts -expect-error: ignore param
940
- await this . send ( "Emulation.setEmulatedMedia" , { type : "screen" } ) ;
945
+ await this . send ( "Emulation.setEmulatedMedia" , { type : "screen" } ) ;
941
946
942
947
// @ts -expect-error: ignore param
943
- const resp = await this . send ( "Page.printToPDF" , { printBackground : true } ) ;
948
+ const resp = await this . send ( "Page.printToPDF" , { printBackground : true } ) ;
944
949
945
950
// @ts -expect-error: ignore param
946
- await this . send ( "Emulation.setEmulatedMedia" , { type : "" } ) ;
951
+ await this . send ( "Emulation.setEmulatedMedia" , { type : "" } ) ;
947
952
948
953
const payload = Buffer . from ( resp . data , "base64" ) ;
949
954
const mime = "application/pdf" ;
@@ -955,35 +960,40 @@ class Recorder {
955
960
statusText : "OK" ,
956
961
pageId : pageInfo . id ,
957
962
mime,
958
- respHeaders : { "Content-Type" : mime , "Content-Length" : payload . length + "" } ,
963
+ respHeaders : {
964
+ "Content-Type" : mime ,
965
+ "Content-Length" : payload . length + "" ,
966
+ } ,
959
967
reqHeaders : { } ,
960
968
payload,
961
- extraOpts : { resource : true } ,
969
+ extraOpts : { resource : true } ,
962
970
} ;
963
971
964
- console . log ( "pdf" , payload . length ) ;
965
-
966
972
// @ts -expect-error - TS2339 - Property '_doAddResource' does not exist on type 'Recorder'.
967
973
await this . _doAddResource ( fullData ) ;
968
974
}
969
975
970
976
// eslint-disable-next-line @typescript-eslint/no-explicit-any
971
977
async saveScreenshot ( pageInfo : any ) {
972
-
973
978
// View Screenshot
974
979
const width = 1920 ;
975
980
const height = 1080 ;
976
981
977
982
// @ts -expect-error: ignore param
978
- await this . send ( "Emulation.setDeviceMetricsOverride" , { width, height, deviceScaleFactor : 0 , mobile : false } ) ;
983
+ await this . send ( "Emulation.setDeviceMetricsOverride" , {
984
+ width,
985
+ height,
986
+ deviceScaleFactor : 0 ,
987
+ mobile : false ,
988
+ } ) ;
979
989
// @ts -expect-error: ignore param
980
- const resp = await this . send ( "Page.captureScreenshot" , { format : "png" } ) ;
990
+ const resp = await this . send ( "Page.captureScreenshot" , { format : "png" } ) ;
981
991
982
992
const payload = Buffer . from ( resp . data , "base64" ) ;
983
- const blob = new Blob ( [ payload ] , { type : "image/png" } ) ;
993
+ const blob = new Blob ( [ payload ] , { type : "image/png" } ) ;
984
994
985
995
await this . send ( "Emulation.clearDeviceMetricsOverride" ) ;
986
-
996
+
987
997
const mime = "image/png" ;
988
998
989
999
const fullData = {
@@ -993,35 +1003,44 @@ class Recorder {
993
1003
statusText : "OK" ,
994
1004
pageId : pageInfo . id ,
995
1005
mime,
996
- respHeaders : { "Content-Type" : mime , "Content-Length" : payload . length + "" } ,
1006
+ respHeaders : {
1007
+ "Content-Type" : mime ,
1008
+ "Content-Length" : payload . length + "" ,
1009
+ } ,
997
1010
reqHeaders : { } ,
998
1011
payload,
999
- extraOpts : { resource : true } ,
1012
+ extraOpts : { resource : true } ,
1000
1013
} ;
1001
1014
1002
1015
const thumbWidth = 640 ;
1003
1016
const thumbHeight = 360 ;
1004
1017
1005
- const bitmap = await self . createImageBitmap ( blob , { resizeWidth : thumbWidth , resizeHeight : thumbHeight } ) ;
1006
-
1018
+ const bitmap = await self . createImageBitmap ( blob , {
1019
+ resizeWidth : thumbWidth ,
1020
+ resizeHeight : thumbHeight ,
1021
+ } ) ;
1022
+
1007
1023
const canvas = new OffscreenCanvas ( thumbWidth , thumbWidth ) ;
1008
1024
const context = canvas . getContext ( "bitmaprenderer" ) ! ;
1009
1025
context . transferFromImageBitmap ( bitmap ) ;
1010
1026
1011
- const resizedBlob = await canvas . convertToBlob ( { type : "image/png" } ) ;
1027
+ const resizedBlob = await canvas . convertToBlob ( { type : "image/png" } ) ;
1012
1028
1013
1029
const thumbPayload = new Uint8Array ( await resizedBlob . arrayBuffer ( ) ) ;
1014
1030
1015
- const thumbData = { ...fullData ,
1031
+ const thumbData = {
1032
+ ...fullData ,
1016
1033
url : "urn:thumbnail:" + pageInfo . url ,
1017
- respHeaders : { "Content-Type" : mime , "Content-Length" : thumbPayload . length + "" } ,
1018
- payload : thumbPayload
1034
+ respHeaders : {
1035
+ "Content-Type" : mime ,
1036
+ "Content-Length" : thumbPayload . length + "" ,
1037
+ } ,
1038
+ payload : thumbPayload ,
1019
1039
} ;
1020
-
1040
+
1021
1041
// @ts -expect-error - TS2339 - Property '_doAddResource' does not exist on type 'Recorder'.
1022
1042
await this . _doAddResource ( fullData ) ;
1023
1043
1024
-
1025
1044
// @ts -expect-error - TS2339 - Property '_doAddResource' does not exist on type 'Recorder'.
1026
1045
await this . _doAddResource ( thumbData ) ;
1027
1046
}
@@ -1470,12 +1489,19 @@ class Recorder {
1470
1489
case "text/javascript" :
1471
1490
case "application/javascript" :
1472
1491
case "application/x-javascript" : {
1473
- const rw = getCustomRewriter ( url , ct === "text/html" ) ;
1492
+ const rw = getCustomRewriter (
1493
+ url ,
1494
+ ct === "text/html" && this . disableMSE ,
1495
+ ) ;
1474
1496
1475
1497
if ( rw ) {
1476
1498
string = payload . toString ( ) ;
1477
1499
newString = rw . rewrite ( string , { save : extraOpts } ) ;
1478
1500
}
1501
+
1502
+ if ( this . disableMSE ) {
1503
+ extraOpts . disableMSE = 1 ;
1504
+ }
1479
1505
}
1480
1506
}
1481
1507
0 commit comments