mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix: avoid override of puppeteer browser
This commit is contained in:
parent
be4adbd366
commit
dde616fbdb
@ -1,8 +1,9 @@
|
|||||||
import { Nuxt } from '../..'
|
import { Nuxt } from '..'
|
||||||
import { loadFixture, getPort } from '../utils'
|
import Browser from './utils/browser'
|
||||||
import * as browser from '../utils/browser'
|
import { loadFixture, getPort } from './utils'
|
||||||
|
|
||||||
let port
|
let port
|
||||||
|
const browser = new Browser()
|
||||||
const url = route => 'http://localhost:' + port + route
|
const url = route => 'http://localhost:' + port + route
|
||||||
|
|
||||||
let nuxt = null
|
let nuxt = null
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { Nuxt, Utils } from '../..'
|
import { Nuxt, Utils } from '..'
|
||||||
import * as browser from '../utils/browser'
|
import Browser from './utils/browser'
|
||||||
import { loadFixture, getPort } from '../utils'
|
import { loadFixture, getPort } from './utils'
|
||||||
|
|
||||||
let port
|
let port
|
||||||
|
const browser = new Browser()
|
||||||
const url = route => 'http://localhost:' + port + route
|
const url = route => 'http://localhost:' + port + route
|
||||||
|
|
||||||
let nuxt = null
|
let nuxt = null
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import puppeteer from 'puppeteer'
|
import puppeteer from 'puppeteer'
|
||||||
|
|
||||||
let browser = null
|
export default class Browser {
|
||||||
|
async start(options = {}) {
|
||||||
export async function start(options = {}) {
|
|
||||||
// https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions
|
// https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions
|
||||||
browser = await puppeteer.launch(
|
this.browser = await puppeteer.launch(
|
||||||
Object.assign(
|
Object.assign(
|
||||||
{
|
{
|
||||||
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
||||||
@ -14,14 +13,14 @@ export async function start(options = {}) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function close() {
|
async close() {
|
||||||
if (!browser) return
|
if (!this.browser) return
|
||||||
await browser.close()
|
await this.browser.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function page(url) {
|
async page(url) {
|
||||||
if (!browser) throw new Error('Please call start() before page(url)')
|
if (!this.browser) throw new Error('Please call start() before page(url)')
|
||||||
const page = await browser.newPage()
|
const page = await this.browser.newPage()
|
||||||
await page.goto(url)
|
await page.goto(url)
|
||||||
await page.waitForFunction('!!window.$nuxt')
|
await page.waitForFunction('!!window.$nuxt')
|
||||||
page.html = () =>
|
page.html = () =>
|
||||||
@ -74,3 +73,4 @@ export async function page(url) {
|
|||||||
}
|
}
|
||||||
return page
|
return page
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user