@@ -39,102 +39,10 @@ const it = base.extend<{
39
39
40
40
it . skip ( ( { isHeadlessShell } ) => isHeadlessShell , 'Headless Shell has no support for extensions' ) ;
41
41
42
- it . describe ( 'MV2' , ( ) => {
43
- it . skip ( ( { channel } ) => channel ?. startsWith ( 'chrome' ) , '--load-extension is not supported in Chrome anymore. https://groups.google.com/a/chromium.org/g/chromium-extensions/c/1-g8EFx2BBY/m/S0ET5wPjCAAJ' ) ;
44
-
45
- it ( 'should return background pages' , async ( { browserType, asset } ) => {
46
- const extensionPath = asset ( 'extension-mv2-simple' ) ;
47
- const extensionOptions = {
48
- args : [
49
- `--disable-extensions-except=${ extensionPath } ` ,
50
- `--load-extension=${ extensionPath } ` ,
51
- ] ,
52
- } ;
53
- const context = await browserType . launchPersistentContext ( '' , extensionOptions ) ;
54
- const backgroundPages = context . backgroundPages ( ) ;
55
- const backgroundPage = backgroundPages . length
56
- ? backgroundPages [ 0 ]
57
- : await context . waitForEvent ( 'backgroundpage' ) ;
58
- expect ( backgroundPage ) . toBeTruthy ( ) ;
59
- expect ( context . backgroundPages ( ) ) . toContain ( backgroundPage ) ;
60
- expect ( context . pages ( ) ) . not . toContain ( backgroundPage ) ;
61
- await context . close ( ) ;
62
- expect ( context . pages ( ) . length ) . toBe ( 0 ) ;
63
- expect ( context . backgroundPages ( ) . length ) . toBe ( 0 ) ;
64
- } ) ;
65
-
66
- it ( 'should return background pages when recording video' , async ( { browserType, asset } , testInfo ) => {
67
- const extensionPath = asset ( 'extension-mv2-simple' ) ;
68
- const extensionOptions = {
69
- args : [
70
- `--disable-extensions-except=${ extensionPath } ` ,
71
- `--load-extension=${ extensionPath } ` ,
72
- ] ,
73
- recordVideo : {
74
- dir : testInfo . outputPath ( '' ) ,
75
- } ,
76
- } ;
77
- const context = await browserType . launchPersistentContext ( '' , extensionOptions ) ;
78
- const backgroundPages = context . backgroundPages ( ) ;
79
- const backgroundPage = backgroundPages . length
80
- ? backgroundPages [ 0 ]
81
- : await context . waitForEvent ( 'backgroundpage' ) ;
82
- expect ( backgroundPage ) . toBeTruthy ( ) ;
83
- expect ( context . backgroundPages ( ) ) . toContain ( backgroundPage ) ;
84
- expect ( context . pages ( ) ) . not . toContain ( backgroundPage ) ;
85
- await context . close ( ) ;
86
- } ) ;
87
-
88
- it ( 'should support request/response events when using backgroundPage()' , async ( { browserType, asset, server } ) => {
89
- server . setRoute ( '/empty.html' , ( req , res ) => {
90
- res . writeHead ( 200 , { 'Content-Type' : 'text/html' , 'x-response-foobar' : 'BarFoo' } ) ;
91
- res . end ( `<span>hello world!</span>` ) ;
92
- } ) ;
93
- const extensionPath = asset ( 'extension-mv2-simple' ) ;
94
- const extensionOptions = {
95
- args : [
96
- `--disable-extensions-except=${ extensionPath } ` ,
97
- `--load-extension=${ extensionPath } ` ,
98
- ] ,
99
- } ;
100
- const context = await browserType . launchPersistentContext ( '' , extensionOptions ) ;
101
- const backgroundPages = context . backgroundPages ( ) ;
102
- const backgroundPage = backgroundPages . length
103
- ? backgroundPages [ 0 ]
104
- : await context . waitForEvent ( 'backgroundpage' ) ;
105
- await backgroundPage . waitForURL ( / c h r o m e - e x t e n s i o n \: \/ \/ .* / ) ;
106
- const [ request , response , contextRequest , contextResponse ] = await Promise . all ( [
107
- backgroundPage . waitForEvent ( 'request' ) ,
108
- backgroundPage . waitForEvent ( 'response' ) ,
109
- context . waitForEvent ( 'request' ) ,
110
- context . waitForEvent ( 'response' ) ,
111
- backgroundPage . evaluate ( url => fetch ( url , {
112
- method : 'POST' ,
113
- body : 'foobar' ,
114
- headers : { 'X-FOOBAR' : 'KEKBAR' }
115
- } ) , server . EMPTY_PAGE ) ,
116
- ] ) ;
117
- expect ( request ) . toBe ( contextRequest ) ;
118
- expect ( response ) . toBe ( contextResponse ) ;
119
- expect ( request . url ( ) ) . toBe ( server . EMPTY_PAGE ) ;
120
- expect ( request . method ( ) ) . toBe ( 'POST' ) ;
121
- expect ( await request . allHeaders ( ) ) . toEqual ( expect . objectContaining ( { 'x-foobar' : 'KEKBAR' } ) ) ;
122
- expect ( request . postData ( ) ) . toBe ( 'foobar' ) ;
123
-
124
- expect ( response . status ( ) ) . toBe ( 200 ) ;
125
- expect ( response . url ( ) ) . toBe ( server . EMPTY_PAGE ) ;
126
- expect ( response . request ( ) ) . toBe ( request ) ;
127
- expect ( await response . text ( ) ) . toBe ( '<span>hello world!</span>' ) ;
128
- expect ( await response . allHeaders ( ) ) . toEqual ( expect . objectContaining ( { 'x-response-foobar' : 'BarFoo' } ) ) ;
129
-
130
- await context . close ( ) ;
131
- } ) ;
132
- } ) ;
133
-
134
42
it . describe ( 'MV3' , ( ) => {
135
43
it . skip ( ( { channel } ) => channel ?. startsWith ( 'chrome' ) , '--load-extension is not supported in Chrome anymore. https://groups.google.com/a/chromium.org/g/chromium-extensions/c/1-g8EFx2BBY/m/S0ET5wPjCAAJ' ) ;
136
44
137
- it ( 'should return background pages ' , async ( { launchPersistentContext, asset } ) => {
45
+ it ( 'should give access to the service worker ' , async ( { launchPersistentContext, asset } ) => {
138
46
const extensionPath = asset ( 'extension-mv3-simple' ) ;
139
47
const context = await launchPersistentContext ( extensionPath ) ;
140
48
const serviceWorkers = context . serviceWorkers ( ) ;
@@ -146,7 +54,7 @@ it.describe('MV3', () => {
146
54
expect ( context . backgroundPages ( ) . length ) . toBe ( 0 ) ;
147
55
} ) ;
148
56
149
- it ( 'should return background pages when recording video' , async ( { launchPersistentContext, asset } , testInfo ) => {
57
+ it ( 'should give access to the service worker when recording video' , async ( { launchPersistentContext, asset } , testInfo ) => {
150
58
const extensionPath = asset ( 'extension-mv3-simple' ) ;
151
59
const context = await launchPersistentContext ( extensionPath , {
152
60
recordVideo : {
@@ -161,7 +69,7 @@ it.describe('MV3', () => {
161
69
await context . close ( ) ;
162
70
} ) ;
163
71
164
- it ( 'should support request/response events when using backgroundPage() ' , async ( { launchPersistentContext, asset, server } ) => {
72
+ it ( 'should support request/response events in the service worker ' , async ( { launchPersistentContext, asset, server } ) => {
165
73
it . fixme ( true , 'Waiting for https://issues.chromium.org/u/1/issues/407795731 getting fixed.' ) ;
166
74
process . env . PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS = '1' ;
167
75
server . setRoute ( '/empty.html' , ( req , res ) => {
0 commit comments