update view port

This commit is contained in:
Joseph 2026-06-17 14:51:32 +07:00
parent 26f894c7bc
commit b7e7ab2b45
2 changed files with 15 additions and 3 deletions

2
.env
View File

@ -1,4 +1,4 @@
PORT=3456
HEADLESS=false
HEADLESS=true
# CHROME_PATH=/Applications/Google Chrome.app/Contents/MacOS/Google Chrome
API_KEY=

View File

@ -40,14 +40,21 @@ class BrowserManager {
console.log(`[${this._tag}] Sử dụng: ${chromePath || 'bundled Chromium'}`);
console.log(`[${this._tag}] Profile : ${this.profileDir}`);
const isHeadless = process.env.HEADLESS === 'true';
// NotebookLM ẩn cột Sources khi cửa sổ quá hẹp — cần viewport rộng
const WIN_W = parseInt(process.env.WINDOW_WIDTH || '1920', 10);
const WIN_H = parseInt(process.env.WINDOW_HEIGHT || '1080', 10);
const opts = {
headless: process.env.HEADLESS === 'true',
headless: isHeadless,
userDataDir: this.profileDir,
defaultViewport: null,
// headless=true: --start-maximized không có tác dụng, phải set viewport tường minh
defaultViewport: isHeadless ? { width: WIN_W, height: WIN_H } : null,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-infobars',
`--window-size=${WIN_W},${WIN_H}`,
'--start-maximized',
'--no-default-browser-check',
'--no-first-run',
@ -76,6 +83,11 @@ class BrowserManager {
this.page = null;
});
// Đảm bảo viewport đủ rộng (headless không auto-maximize)
if (isHeadless) {
await this.page.setViewport({ width: WIN_W, height: WIN_H });
}
// macOS: kéo cửa sổ lên trước (chỉ slot 0)
if (process.platform === 'darwin' && this.slotIndex === 0) {
setTimeout(() => {