@@ -331,45 +331,49 @@ export async function addPageResources(page, options) {
331331 * to be cleared.
332332 */
333333export async function clearPageResources ( page , injectedResources ) {
334- for ( const resource of injectedResources ) {
335- await resource . dispose ( ) ;
336- }
334+ try {
335+ for ( const resource of injectedResources ) {
336+ await resource . dispose ( ) ;
337+ }
337338
338- // Destroy old charts after export is done and reset all CSS and script tags
339- await page . evaluate ( ( ) => {
340- // We are not guaranteed that Highcharts is loaded, e,g, when doing SVG
341- // exports
342- if ( typeof Highcharts !== 'undefined' ) {
343- // eslint-disable-next-line no-undef
344- const oldCharts = Highcharts . charts ;
345-
346- // Check in any already existing charts
347- if ( Array . isArray ( oldCharts ) && oldCharts . length ) {
348- // Destroy old charts
349- for ( const oldChart of oldCharts ) {
350- oldChart && oldChart . destroy ( ) ;
351- // eslint-disable-next-line no-undef
352- Highcharts . charts . shift ( ) ;
339+ // Destroy old charts after export is done and reset all CSS and script tags
340+ await page . evaluate ( ( ) => {
341+ // We are not guaranteed that Highcharts is loaded, e,g, when doing SVG
342+ // exports
343+ if ( typeof Highcharts !== 'undefined' ) {
344+ // eslint-disable-next-line no-undef
345+ const oldCharts = Highcharts . charts ;
346+
347+ // Check in any already existing charts
348+ if ( Array . isArray ( oldCharts ) && oldCharts . length ) {
349+ // Destroy old charts
350+ for ( const oldChart of oldCharts ) {
351+ oldChart && oldChart . destroy ( ) ;
352+ // eslint-disable-next-line no-undef
353+ Highcharts . charts . shift ( ) ;
354+ }
353355 }
354356 }
355- }
356357
357- // eslint-disable-next-line no-undef
358- const [ ...scriptsToRemove ] = document . getElementsByTagName ( 'script' ) ;
359- // eslint-disable-next-line no-undef
360- const [ , ...stylesToRemove ] = document . getElementsByTagName ( 'style' ) ;
361- // eslint-disable-next-line no-undef
362- const [ ...linksToRemove ] = document . getElementsByTagName ( 'link' ) ;
363-
364- // Remove tags
365- for ( const element of [
366- ...scriptsToRemove ,
367- ...stylesToRemove ,
368- ...linksToRemove
369- ] ) {
370- element . remove ( ) ;
371- }
372- } ) ;
358+ // eslint-disable-next-line no-undef
359+ const [ ...scriptsToRemove ] = document . getElementsByTagName ( 'script' ) ;
360+ // eslint-disable-next-line no-undef
361+ const [ , ...stylesToRemove ] = document . getElementsByTagName ( 'style' ) ;
362+ // eslint-disable-next-line no-undef
363+ const [ ...linksToRemove ] = document . getElementsByTagName ( 'link' ) ;
364+
365+ // Remove tags
366+ for ( const element of [
367+ ...scriptsToRemove ,
368+ ...stylesToRemove ,
369+ ...linksToRemove
370+ ] ) {
371+ element . remove ( ) ;
372+ }
373+ } ) ;
374+ } catch ( error ) {
375+ logWithStack ( 2 , error , `[browser] Could not clear page's resources.` ) ;
376+ }
373377}
374378
375379/**
0 commit comments