Skip to content

Commit

Permalink
feat(page): add method to get remote debugging url
Browse files Browse the repository at this point in the history
  • Loading branch information
brewcoua committed Jun 13, 2024
1 parent f8d5687 commit 665c275
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/services/browser/BrowserConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const REMOTE_PORT = 9394
const config: BrowserConfig = {
type: 'chromium',
options: {
headless: false,
headless: true,
args: [
'--disable-web-security',
`--remote-debugging-port=${REMOTE_PORT}`,
Expand Down
18 changes: 17 additions & 1 deletion src/services/browser/wrappers/PageWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Page } from 'playwright'
import { mkdirSync, readFileSync } from 'node:fs'
import { Logger } from 'winston'

import config from '../BrowserConfig'
import config, { REMOTE_PORT } from '../BrowserConfig'

import Action from '../../../services/runner/domain/Action'
import ActionType from '../../../services/runner/domain/ActionType'
Expand Down Expand Up @@ -55,6 +55,22 @@ export default class PageWrapper {
}
}

public async getRemoteDebuggingUrl(): Promise<string | null> {
const pages = await fetch(`http://localhost:${REMOTE_PORT}/json`)
.then((res) => res.json())
.catch(() => [])

const title = await this.title()
const page = pages.find(
(p: any) =>
p.type === 'page' && p.url === this.url && p.title === title
)

return page
? `http://localhost:${REMOTE_PORT}${page.devtoolsFrontendUrl}`
: null
}

/**
* Take a screenshot of the current page
*
Expand Down
8 changes: 4 additions & 4 deletions src/services/runner/Runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import { Logger } from 'winston'

export default class Runner extends Service {
constructor(
private readonly page: PageWrapper,
private readonly mind: MindService,
private readonly task: string,
private readonly id: number,
public readonly page: PageWrapper,
public readonly mind: MindService,
public readonly task: string,
public readonly id: number,
logger: Logger
) {
super('Runner', logger.child({ id }))
Expand Down

0 comments on commit 665c275

Please sign in to comment.