mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-24 06:11:11 -05:00
Allow selection of multiple browser viewport sizes and adjusting screenshot quality
This commit is contained in:
@@ -58,9 +58,11 @@ export class BrowserSession {
|
||||
"--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
|
||||
],
|
||||
executablePath: stats.executablePath,
|
||||
defaultViewport: await this.context.globalState.get("browserLargeViewport")
|
||||
? { width: 1280, height: 800 }
|
||||
: { width: 900, height: 600 },
|
||||
defaultViewport: (() => {
|
||||
const size = (this.context.globalState.get("browserViewportSize") as string | undefined) || "900x600"
|
||||
const [width, height] = size.split("x").map(Number)
|
||||
return { width, height }
|
||||
})(),
|
||||
// headless: false,
|
||||
})
|
||||
// (latest version of puppeteer does not add headless to user agent)
|
||||
@@ -134,7 +136,7 @@ export class BrowserSession {
|
||||
let screenshotBase64 = await this.page.screenshot({
|
||||
...options,
|
||||
type: "webp",
|
||||
quality: 100, // Set maximum quality to prevent compression artifacts
|
||||
quality: (await this.context.globalState.get("screenshotQuality") as number | undefined) ?? 75,
|
||||
})
|
||||
let screenshot = `data:image/webp;base64,${screenshotBase64}`
|
||||
|
||||
@@ -245,27 +247,29 @@ export class BrowserSession {
|
||||
}
|
||||
|
||||
async scrollDown(): Promise<BrowserActionResult> {
|
||||
const isLargeViewport = await this.context.globalState.get("browserLargeViewport")
|
||||
const size = (await this.context.globalState.get("browserViewportSize") as string | undefined) || "900x600"
|
||||
const height = parseInt(size.split("x")[1])
|
||||
return this.doAction(async (page) => {
|
||||
await page.evaluate((scrollHeight) => {
|
||||
window.scrollBy({
|
||||
top: scrollHeight,
|
||||
behavior: "auto",
|
||||
})
|
||||
}, isLargeViewport ? 800 : 600)
|
||||
}, height)
|
||||
await delay(300)
|
||||
})
|
||||
}
|
||||
|
||||
async scrollUp(): Promise<BrowserActionResult> {
|
||||
const isLargeViewport = await this.context.globalState.get("browserLargeViewport")
|
||||
const size = (await this.context.globalState.get("browserViewportSize") as string | undefined) || "900x600"
|
||||
const height = parseInt(size.split("x")[1])
|
||||
return this.doAction(async (page) => {
|
||||
await page.evaluate((scrollHeight) => {
|
||||
window.scrollBy({
|
||||
top: -scrollHeight,
|
||||
behavior: "auto",
|
||||
})
|
||||
}, isLargeViewport ? 800 : 600)
|
||||
}, height)
|
||||
await delay(300)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user