@@ -10,6 +10,7 @@ import type { LighthouseReport, PuppeteerTask, UnlighthouseRouteReport } from '.
10
10
import { useUnlighthouse } from '../../unlighthouse'
11
11
import { useLogger } from '../../logger'
12
12
import { ReportArtifacts , base64ToBuffer } from '../../util'
13
+ import { setupPage } from '../util'
13
14
14
15
export function normaliseLighthouseResult ( route : UnlighthouseRouteReport , result : LH . Result ) : LighthouseReport {
15
16
const { resolvedConfig, runtimeSettings } = useUnlighthouse ( )
@@ -85,7 +86,7 @@ export function normaliseLighthouseResult(route: UnlighthouseRouteReport, result
85
86
86
87
export const runLighthouseTask : PuppeteerTask = async ( props ) => {
87
88
const logger = useLogger ( )
88
- const { resolvedConfig, runtimeSettings, worker, hooks } = useUnlighthouse ( )
89
+ const { resolvedConfig, runtimeSettings, worker } = useUnlighthouse ( )
89
90
const { page, data : routeReport } = props
90
91
91
92
// if the report doesn't exist, we're going to run a new lighthouse process to generate it
@@ -96,32 +97,9 @@ export const runLighthouseTask: PuppeteerTask = async (props) => {
96
97
return routeReport
97
98
}
98
99
99
- const browser = page . browser ( )
100
- const port = new URL ( browser . wsEndpoint ( ) ) . port
101
- // ignore csp errors
102
- await page . setBypassCSP ( true )
103
-
104
- if ( resolvedConfig . auth )
105
- await page . authenticate ( resolvedConfig . auth )
106
-
107
- if ( resolvedConfig . cookies )
108
- await page . setCookie ( ...resolvedConfig . cookies )
109
- if ( resolvedConfig . extraHeaders )
110
- await page . setExtraHTTPHeaders ( resolvedConfig . extraHeaders )
111
-
112
- // Wait for Lighthouse to open url, then allow hook to run
113
- browser . on ( 'targetchanged' , async ( target ) => {
114
- const page = await target . page ( )
115
- if ( page ) {
116
- // in case they get reset
117
- if ( resolvedConfig . cookies )
118
- await page . setCookie ( ...resolvedConfig . cookies )
119
- if ( resolvedConfig . extraHeaders )
120
- await page . setExtraHTTPHeaders ( resolvedConfig . extraHeaders )
121
- await hooks . callHook ( 'puppeteer:before-goto' , page )
122
- }
123
- } )
100
+ await setupPage ( page )
124
101
102
+ const port = new URL ( page . browser ( ) . wsEndpoint ( ) ) . port
125
103
// allow changing behavior of the page
126
104
const clonedRouteReport = { ...routeReport }
127
105
// just modify the url for the unlighthouse request
0 commit comments