1.82.0 • Published 3 years ago

@lcrespilho/puppeteer-utils v1.82.0

Weekly downloads
230
License
ISC
Repository
-
Last release
3 years ago

Classes

Functions

Typedefs

PuppeteerVideoRecorder

Kind: global class

new PuppeteerVideoRecorder()

Utiliza ffmpeg para gravar a sessão.

Example

const record = new PuppeteerVideoRecorder(page, 'myRecord');
  await record.start();
  await page.goto(...);
  await record.stop();
  // será criado o arquivo myRecord.mp4 no diretório atual.

puppeteerVideoRecorder.screencastFrameHandler()

Listener para o evento 'Page.screencastframe'.

Kind: instance method of PuppeteerVideoRecorder
Pardam: puppeteer.Protocol.Page.ScreencastFrameEvent _

PuppeteerVideoRecorder.PuppeteerVideoRecorder

Kind: static class of PuppeteerVideoRecorder

new PuppeteerVideoRecorder(page, label)

Creates an instance of PuppeteerVideoRecorder.

ParamTypeDefaultDescription
pagepuppeteer.Page
labelstring"'record'"caminho relativo e nome do arquivo a ser gravado, sem especificar a extensão. Ex: "public/record" => arquivo record.mp4 em "./public". Default = 'record'.

PuppeteerVideoRecorder.PuppeteerVideoRecorder : Array.<Frame>

Kind: static property of PuppeteerVideoRecorder

new PuppeteerVideoRecorder(page, label)

Creates an instance of PuppeteerVideoRecorder.

ParamTypeDefaultDescription
pagepuppeteer.Page
labelstring"'record'"caminho relativo e nome do arquivo a ser gravado, sem especificar a extensão. Ex: "public/record" => arquivo record.mp4 em "./public". Default = 'record'.

PuppeteerVideoRecorder.normalizeFrames(frames)

Normaliza o array de Frame's realizando as seguintes ações: 1. transforma a propriedade timestamp, de float para natural, fazendo: - subtrai, de todos os timestamps, o timestamp do primeiro Frame. - divide todos os timestamps por 0.04s, que corresponde a 25fps: taxa escolhida para criar o vídeo de saída. 2. expande o array original, preenchendo os frames ausentes para formar um vídeo com 25fps. 3. adiciona 2s de repetição do último frame, para dar tempo de vê-lo antes do player fechar.

Kind: static method of PuppeteerVideoRecorder

ParamType
framesArray.<Frame>

Example

Entrada: [{frameBuffer: f1, timestamp: 10.6}, {frameBuffer: f2, timestamp: 10.68}, {frameBuffer: f3, timestamp: 10.76}]
  Saída: [{frameBuffer: f1, timestamp: 0}, {frameBuffer: f1, timestamp: 1}, {frameBuffer: f2, timestamp: 2}, {frameBuffer: f2, timestamp: 3}, {frameBuffer: f3, timestamp: 4}]

getFrameBlockTypes(page, site)

Verifica se o site do cliente bloqueia iframes same-origin ou other-origin, e se implementa Frame Busting.

Kind: global function

ParamTypeDescription
pagepuppeteer.Page
sitestringSite do cliente.

waitForNetworkIdle(page, timeout, maxInflightRequests) ⇒ Promise.<string>

Network-idle watcher. Wait until inflight requests <= maxInflightRequests for at least timeout ms. Returns the last seen resource. E.g.:

Kind: global function
Returns: Promise.<string> - the last seen resource.

ParamTypeDefaultDescription
pagepuppeteer.Page
timeoutnumber500minimum time span with the condition inflight requests <= maxInflightRequests holded, to consider the network idle.
maxInflightRequestsnumber0maximum inflight requests to consider the network idle.

waitForEvent(page, event, timeout)

The methods page.waitForNavigation and frame.waitForNavigation wait for the page event domcontentloaded at minimum. This function returns a promise that resolves as soon as the specified page event happens.

Kind: global function

ParamTypeDescription
pagepuppeteer.Page
event'close' | 'console' | 'dialog' | 'domcontentloaded' | 'error' | 'frameattached' | 'framedetached' | 'framenavigated' | 'load' | 'metrics' | 'pageerror' | 'popup' | 'request' | 'requestfailed' | 'requestfinished' | 'response' | 'workercreated' | 'workerdestroyed'Can be any event accepted by the method page.on(). E.g.: "requestfinished" or "framenavigated".
timeoutnumberoptional time to wait. If not specified, waits forever.

waitForRequestFinished(page, requestUrl, timeout)

The methods page.waitForNavigation and frame.waitForNavigation wait for the page event domcontentloaded at minimum. This function returns a promise that resolves as soon as the specified requestUrl resource has finished downloading, or timeout elapses.

Kind: global function

ParamTypeDescription
pagepuppeteer.Page
requestUrlstringpass the exact url of the resource you want to wait for. Paths must be ended with slash "/". Don't forget that.
timeoutnumberoptional time to wait. If not specified, waits forever.

createFrame(page, frameName)

Cria um iframe novo e o retorna.

Kind: global function

ParamTypeDescription
pagepuppeteer.Page
frameNamestringnome do frame criado

waitForFrame(page, frameName, timeout) ⇒ Promise.<puppeteer.Frame> | Promise.<undefined>

Retorna uma promise que resolve com o primeiro frame que surgir em page com nome frameName. Aguarda no máximo timeout ms, ou infinito se timout for omitido.

Kind: global function

ParamTypeDescription
pagepuppeteer.Pagepágina onde se deseja encontrar o frame.
frameNamestringnome do frame procurado em page.
timeoutnumbertempo máximo de espera. Se não especificado, aguarda infinitamente pela existência de frameName em page.

getPerformanceMetrics(page)

Retorna um objeto contendo algumas métricas importantes de performance. Como essa função retorna métricas de carregamento, é importante garantir que essa função só será chamada após a página terminar de carregar, preferencialmente por completo. Esta função não garante isso; quem tem que garantir é o código chamador.

Kind: global function

ParamTypeDescription
pagepuppeteer.Pagepágina

getRedirectChain(response) ⇒ Array.<string>

Retorna o chain de redirects de uma requisição fetch (qualquer recurso, não somente navegações).

Kind: global function
Returns: Array.<string> - Array de urls que participaram do chain de redirects. Se não teve redirects, retorna a url do response passado como argumento.

ParamTypeDescription
responsepuppeteer.HTTPResponseResponse associado ao request que gerou o chain de redirects.

pageRedirectRequest(page, redirects, requestAlreadyHandled) ⇒

Cria redirect(s) 307.

Kind: global function
Returns: Retorna uma função que desativa o(s) redirect(s).

ParamTypeDefaultDescription
pagepuppeteer.Page
redirectsArray.<redirect>Array de regras de redirect
requestAlreadyHandledbooleanfalseSe true, indica que esta função não deve executar request.continue(), caso já executado por outro listener.

waitForSelector(page, selector)

Extensão ao método page.waitForSelector que aceita seletores AND (comma). Tem o funcionamento similar ao expect(page).toClick(selector, options) do pacote expect-puppeteer.

Kind: global function

ParamTypeDescription
pagepuppeteer.Page
selectorstringSeletor contendo ou não regras AND

emulateMobile(page)

Emula um mobile "Nexus 5X".

Kind: global function

ParamType
pagepuppeteer.Page

emulateDesktop(page) ⇒ Promise.<any>

Emula um desktop 1800x900, userAgent Chrome 83.

Kind: global function

ParamType
pagepuppeteer.Page

closeOtherPages(page) ⇒ Promise.<any>

Fecha todas as abas do BrowserContext de page passada como parâmetro, com exceção dela própria.

Kind: global function

ParamType
pagepuppeteer.Page

closeAllOtherPages(page) ⇒ Promise.<any>

Fecha todas as abas do browser (de todos os contextos), com exceção de page passada como parâmetro.

Kind: global function

ParamType
pagepuppeteer.Page

beaconizeCollectHits(page)

Transform POST collect requests into GET requests, in order to facilitate in matching its contents.

Kind: global function

ParamType
pagepuppeteer.Page

defineDataLayerUtils(page)

Define dataModel and Observe dataLayer on the page.

Kind: global function

ParamType
pagepuppeteer.Page

toMatchDatalayerObject(mockFn, expectObjectSubset)

Matcher para push de dataLayer. Uso: expect(mockFn).toMatchDatalayerObject({event: 'sendTransaction'})

Kind: global function

ParamTypeDescription
mockFnjest.Mock.<any, any>Mock do dataLayer.push
expectObjectSubsetObjectSubconjunto do objeto que se deseja pesquisar no mock do dataLayer.push

get(path)

Data Layer Model get method.

Kind: global function

ParamTypeDescription
pathstringThe path of the property on the model. If undefined, returns the entire representation of the model.

set(path, value)

Data Layer Model set method.

Kind: global function

ParamTypeDescription
pathstringThe of the property on the model. E.g.: 'a.b.c'
value*The value to set on the property. E.g.: 1,2,3

validateCollectEvent(category, action, label, value, regexesOrStrings)

Helper para validação de eventos de collects

Kind: global function

ParamTypeDescription
categorystringcategoria do hit
actionstringaction do hit
labelstringlabel do hit
valuenumbervalor inteiro
regexesOrStringsArray.<(RegExp|string)>Array de regex ou string para dar match no collect, não importa a ordem

validateCollectEvent~predicate(req)

Kind: inner method of validateCollectEvent

ParamType
reqpuppeteer.HTTPRequest

redirect : Object

Regra de redirect.

Kind: global typedef
Properties

NameTypeDefault
requestMatchRegExp
resourceType'document' | 'stylesheet' | 'image' | 'media' | 'font' | 'script' | 'texttrack' | 'xhr' | 'fetch' | 'ping' | 'eventsource' | 'websocket' | 'manifest' | 'other'
redirectLocationstring"'about:blank'"

dlPushListener : function

Generic callback for dataLayer push.

Kind: global typedef

ParamTypeDescription
dlPayload*Payload de dataLayer

Frame : Object

Objeto contendo 1 Buffer representando o frame/imagem, e seu timestamp correspondente.

Kind: global typedef
Properties

NameTypeDescription
timestampnumberTimestamp do frame
frameBufferBufferrepresentação em buffer da string base64 que representa a imagem.
1.82.0

3 years ago

1.81.0

3 years ago

1.80.0

3 years ago

1.78.0

3 years ago

1.76.0

3 years ago

1.75.0

3 years ago

1.77.0

3 years ago

1.74.0

3 years ago

1.73.0

3 years ago

1.72.0

3 years ago

1.71.0

3 years ago

1.70.0

3 years ago

1.67.0

3 years ago

1.69.0

3 years ago

1.66.0

3 years ago

1.68.0

3 years ago

1.65.0

3 years ago

1.64.0

3 years ago

1.63.0

3 years ago

1.62.0

3 years ago

1.61.0

4 years ago

1.60.0

4 years ago

1.59.0

4 years ago

1.58.0

4 years ago

1.56.0

4 years ago

1.57.0

4 years ago

1.55.0

4 years ago

1.54.0

4 years ago

1.53.0

4 years ago

1.52.0

4 years ago

1.51.0

4 years ago

1.50.0

4 years ago

1.49.0

4 years ago

1.48.0

4 years ago

1.47.0

4 years ago

1.46.0

4 years ago

1.45.0

4 years ago

1.44.0

4 years ago

1.42.0

4 years ago

1.41.0

4 years ago

1.43.0

4 years ago

1.40.0

4 years ago

1.38.0

4 years ago

1.37.0

4 years ago

1.36.0

4 years ago

1.35.0

4 years ago

1.34.0

4 years ago

1.33.0

4 years ago

1.22.0

4 years ago

1.25.0

4 years ago

1.26.0

4 years ago

1.23.0

4 years ago

1.24.0

4 years ago

1.29.0

4 years ago

1.27.0

4 years ago

1.28.0

4 years ago

1.32.0

4 years ago

1.30.0

4 years ago

1.31.0

4 years ago

1.21.0

4 years ago

1.20.0

4 years ago

1.19.0

5 years ago

1.18.0

5 years ago

1.17.0

5 years ago

1.16.0

5 years ago

1.15.0

5 years ago

1.14.0

5 years ago

1.13.0

5 years ago

1.12.0

5 years ago

1.11.0

5 years ago

1.10.0

5 years ago

1.8.0

5 years ago

1.7.0

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago