update
This commit is contained in:
47
src/test/pane.ts
Normal file
47
src/test/pane.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { Command } from "commander";
|
||||
import { core, program, exit } from './common.ts'
|
||||
// import size from 'window-size'
|
||||
const main = async () => {
|
||||
const connected = await core.connect();
|
||||
if (!connected) {
|
||||
console.log('无法连接到浏览器实例,程序退出');
|
||||
process.exit(1);
|
||||
}
|
||||
const page = core.page!;
|
||||
|
||||
// 设置页面视口大小
|
||||
const browser = core.browser!;
|
||||
const cdp = await page.context().newCDPSession(page);
|
||||
const { windowId } = await cdp.send('Browser.getWindowForTarget');
|
||||
// 第一个窗口(左侧)
|
||||
// await cdp.send('Browser.setWindowBounds', {
|
||||
// windowId,
|
||||
// bounds: { left: -1920, top: 0 }
|
||||
// });
|
||||
// 如何获取屏幕宽度
|
||||
// const { width, height } = size.get();
|
||||
// console.log(`屏幕宽度: ${width}, 高度: ${height}`);
|
||||
// await page.goto('https://www.xiaohongshu.com/');
|
||||
await cdp.send('Browser.setWindowBounds', {
|
||||
windowId,
|
||||
bounds: {
|
||||
windowState: 'maximized'
|
||||
}
|
||||
});
|
||||
// 开启全屏
|
||||
|
||||
// const session = await page.context().newCDPSession(page);
|
||||
// await session.send('Emulation.setDeviceMetricsOverride', {
|
||||
// width: 1920,
|
||||
// height: 1080,
|
||||
// deviceScaleFactor: 1,
|
||||
// mobile: false,
|
||||
// });
|
||||
exit(0)
|
||||
}
|
||||
|
||||
export const paneCommand = new Command('pane').action(async () => {
|
||||
await main();
|
||||
});
|
||||
|
||||
program.addCommand(paneCommand);
|
||||
Reference in New Issue
Block a user