How to use setWindowBounds method in Playwright Internal

Best JavaScript code snippet using playwright-internal

index.js

Source:index.js Github

copy

Full Screen

1// imports2 import path from 'path';3 import fs from 'fs';4 import * as Service from './service.js';5 import * as Common from './lib/common.js';6 import CONFIG from './config.js';7// constants8 const PROBE_SCREEN = true;9 const callId = () => (99999*Math.random()+Date.now()).toString(36);10 const {sleep, DEBUG, DEBUG2} = Common;11 // simple key value store12 const KV = {};13 const HasListeners = new Map();14// main export15 // note that these calls with UI = App.UI16 // will run against the default (the first) UI created.17 // but only when called directly from the service side.18 // when called from UI side, the calls that have a UI parameter19 // are called on the UI that makes the call or, if the UI parameter is a string20 // called on the UI having the name equal to that string.21 // before the App opens a window or22 // if the 'default' UI is closed there will be no default UI23 // and calls made from the service side on functions24 // requiring a UI parameter and without specifying a UI 25 // parameter will fail at that time26 // until a new UI (window) is opened (via API.ui.open())27 const API = {28 go, // start app launch sequence29 stop, // kill app, cleanup, and exit (after async jobs parameter completes)30 say, // say something to console (throws if console closed)31 ui : {32 open, // open UI window33 close, // close UI window34 move, // move UI window (throws if no window open)35 size, // size UI window (throws if no window open)36 minimize, // minimize UI window (throws if no window open)37 maximize, // maximize UI window (throws if no window open)38 restore, // switch between maximize and how it was before39 fullscreen, // UI window to fullscreen40 partscreen, // UI window to part of screen41 getLayout, // get window left, right, width, height and windowState42 openBlank, // open a UI window to about:blank43 writePage, // like document.write if using a custom window control box, writes to the44 // iframe document inside that45 getScreen, // get screen dimensions46 },47 meta: {48 getStartURL, // gets the start URL for the app 49 getFavicon, // gets a (or an optionally named) favicon as a data URL50 getTitle, // gets the app title51 },52 control: {53 send, // send a DevTools command (throws if ui not connected yet)54 on, // start listening for a DevTools event (throws if ui not connected yet)55 off, // stop listening for a DevTools event (throws if ui not connected yet)56 },57 util: {58 sleep,59 kv: save, // save a (key, value) pair60 k: load, // getrieve a key61 d: del,62 hasKey // returns a promise that resolves when a key is set63 },64 _serviceOnly: {65 publishAPI, // publish an API into the UI context (requires apiInUI: true)66 getUI,67 getApp68 }69 };70export default API;71// state variables72 let App;73// basic functions74 async function go({75 uiName:76 uiName = undefined, // name for first window opened (if any) 77 apiInUI: // enable grader API available in UI context78 apiInUI = false,79 addHandlers:80 addHandlers = undefined, // callback to add the route handlers to an express app81 server:82 server = null, // used to replace the default server83 // if you don't want a server or if you need 84 // more control (such as websockets, or TLS)85 // we call listen automatically86 keepConsoleOpen:87 keepConsoleOpen = false, // keeps the console open in case you need it88 doLayout: 89 doLayout = true, // control window layout on screen90 // true for auto centered mode (default) or91 // a function with signature: ({screenWidth, screenHeight}) => 92 // {screenWidth, screenHeight, x, y, width, height}93 // to set the x,y,width,height base on screenWidth and screenHeight94 keepAlive: 95 keepAlive = false, // keeps the service running after all windows closed96 // until it is explicitly killed with stop97 noWindow:98 noWindow = false, // starts the service but doesn't open a window99 } = {}) {100 App = await Service.go({101 uiName, 102 apiInUI, addHandlers, 103 server, keepConsoleOpen, doLayout, keepAlive, noWindow104 });105 return App;106 }107 async function stop() {108 if ( !App ) {109 throw new TypeError(110 `API.stop can only be called if App has started and is not already stopped.`111 );112 }113 await App.killService();114 }115 async function say(msg) {116 try {117 await App.notify(msg);118 } catch(e) {119 DEBUG && console.info("say.App.notify", e);120 throw new TypeError(121 `Cannot API.say a console message because App Console has already closed.`122 );123 }124 }125// window functions126 async function open(settings) {127 if ( ! App ) throw new TypeError(`Need to call API.go first to create App before opening additional windows.`);128 const {uis,ServicePort} = App;129 const {uiName: name, keepService, uriPath} = settings;130 const sessionId = Common.newSessionId();131 // do layout prep if requrested132 let layout;133 if ( settings.doLayout ) {134 let screenWidth, screenHeight;135 if ( PROBE_SCREEN ) {136 ({screenWidth, screenHeight} = await getScreen({137 ServicePort, 138 /*139 sessionId,140 */141 uis142 }));143 } else {144 screenWidth = 800;145 screenHeight = 600;146 }147 layout = {screenWidth, screenHeight};148 if ( typeof settings.doLayout === "function" ) {149 layout = settings.doLayout(layout);150 }151 }152 fs.writeFileSync('grader.open.log', JSON.stringify({ServicePort, sessionId}));153 let browser, UI;154 try {155 ({UI,browser} = await Service.newBrowser({156 uis,157 ServicePort, sessionId, layout, name,158 keepService,159 uriPath160 }));161 // if not UI yet, this is the first so set it as default162 if ( ! App.UI ) {163 App.UI = UI;164 }165 } catch(e) {166 console.log("open.newBrowser", e);167 fs.writeFileSync('grader.error', JSON.stringify({err:e, msg:e+''}));168 }169 // don't expose socket170 UI.socket = null;171 return {UI,browser};172 }173 async function close(UI = App.UI) {174 const call = callId();175 const {browserSessionId,id} = UI;176 DEBUG2 && console.info({browserSessionId,id,call,close:1});177 const errors = [];178 if ( ! UI.disconnected ) {179 try {180 DEBUG2 && console.info({browserSessionId,id,call,close:2});181 await UI.send("Browser.close", {}); 182 DEBUG2 && console.info({browserSessionId,id,call,close:3});183 } catch(e) {184 DEBUG2 && console.info('Error closing browser', e);185 errors.push({msg:'error closing browser', e});186 }187 try {188 DEBUG2 && console.info({browserSessionId,id,call,close:4});189 UI.disconnect();190 DEBUG2 && console.info({browserSessionId,id,call,close:5});191 } catch(e) {192 DEBUG2 && console.info(`Error disconnecting socket`, e);193 errors.push({msg:'error disconnecting socket', e});194 }195 } 196 // does not work197 //await sleep(1000);198 try {199 await UI.browser.kill();200 } catch(e) {201 DEBUG2 && console.info(`Error kill browser`, e);202 errors.push({msg:'error kill browser', e});203 }204 try {205 DEBUG2 && console.info({browserSessionId,id,call,close:6});206 UI.cleanSessionDirs();207 DEBUG2 && console.info({browserSessionId,id,call,close:7});208 } catch(e) {209 DEBUG2 && console.info(`Error shut down browser.`, e);210 errors.push({msg:'error UI.cleanSessionDirs', e});211 }212 DEBUG2 && console.info({browserSessionId,id,call,close:8});213 if ( errors.length ) {214 DEBUG2 && console.log(`API.ui.close`, errors);215 return {status:'fail', errors};216 } else {217 DEBUG2 && console.log(`API.ui.close`, 'success');218 return {status:'success'};219 }220 }221 async function move({x,y}, UI = App.UI) {222 UI.x = x;223 UI.y = y;224 return await UI.send("Browser.setWindowBounds", {225 windowId: UI.windowId,226 bounds: {227 left: x,228 top: y229 }230 });231 }232 async function size({width,height}, UI = App.UI) {233 /*234 await UI.send("Emulation.setDeviceMetricsOverride", {235 mobile: false,236 width,237 height,238 deviceScaleFactor: 1,239 screenOrientation: {240 angle: 0,241 type: 'portraitPrimary'242 },243 });244 */245 await UI.send("Browser.setWindowBounds", {246 windowId: UI.windowId,247 bounds: {248 windowState: 'normal',249 width:0,250 height:0251 }252 });253 const result = await UI.send("Browser.setWindowBounds", {254 windowId: UI.windowId,255 bounds: {256 windowState: 'normal',257 width,258 height259 }260 });261 UI.width = width;262 UI.height = height;263 return result;264 }265 async function minimize(UI = App.UI) {266 const {windowState} = await getLayout();267 if ( windowState == 'minimized' ) return;268 const result = await UI.send("Browser.setWindowBounds", {269 windowId: UI.windowId,270 bounds: {271 windowState: 'minimized'272 }273 });274 return result;275 }276 async function restore(UI = App.UI) {277 const {windowState} = await getLayout();278 let result;279 if ( windowState == 'maximized' ) {280 result = await UI.send("Browser.setWindowBounds", {281 windowId: UI.windowId,282 bounds: {283 windowState: 'normal'284 }285 });286 } else {287 result = await UI.send("Browser.setWindowBounds", {288 windowId: UI.windowId,289 bounds: {290 windowState: 'maximized'291 }292 });293 }294 return result;295 }296 async function maximize(UI = App.UI) {297 const {windowState} = await getLayout();298 if ( windowState == 'minimized' ) {299 await partscreen(UI);300 }301 const result = await UI.send("Browser.setWindowBounds", {302 windowId: UI.windowId,303 bounds: {304 windowState: 'maximized'305 }306 });307 return result;308 }309 async function fullscreen(UI = App.UI) {310 const {windowState} = await getLayout();311 if ( windowState == 'minimized' ) {312 await partscreen(UI);313 }314 const result = await UI.send("Browser.setWindowBounds", {315 windowId: UI.windowId,316 bounds: {317 windowState: 'fullscreen'318 }319 });320 return result;321 }322 async function partscreen(UI = App.UI) {323 const {windowState} = await getLayout();324 if ( windowState == 'normal' ) return;325 const result = await UI.send("Browser.setWindowBounds", {326 windowId: UI.windowId,327 bounds: {328 windowState: 'normal'329 }330 });331 return result;332 }333 async function getLayout(UI = App.UI) {334 const {bounds} = await UI.send("Browser.getWindowBounds", {335 windowId: UI.windowId336 });337 return bounds;338 }339// window functions part ii340 async function openBlank() {341 throw new TypeError(`Not implemented yet.`);342 }343 async function writePage() {344 throw new TypeError(`Not implemented yet.`);345 }346// meta functions347 async function getStartURL(UI = App.UI) {348 return UI.startUrl;349 }350 async function getFavicon() {351 const iconPath = path.resolve(Service.SITE_PATH, '_icons', 'favicon.ico'); 352 const base64Icon = fs.readFileSync(iconPath, {encoding:'base64'});353 const dataURL = `data:image/ico;base64,${base64Icon}`;354 return dataURL;355 }356 async function getTitle() {357 return CONFIG.name;358 }359// window functions part iii360 async function getScreen({ServicePort, sessionId: providedSessionId, uis} = {}) {361 console.log(`Getting screen`);362 let screen = load('screen');363 if ( !screen ) {364 // open a headless browser to a page that sends us the screen details365 let UI;366 try {367 ({UI} = await Service.newBrowser({368 uis,369 silent: true,370 headless: true, 371 uriPath: '/_api/getscreen.html',372 ServicePort, 373 sessionId: providedSessionId || Common.newSessionId(),374 // we will delete directories unless provided with a sessionId375 // which can save time for main UI startup as the headless376 // window prepares all the session directories377 noDelete: providedSessionId ? true : false,378 // we don't want to kill the whole service when we close this UI379 // and we have no other UIs open380 // since often this UI comes before others to provide the screen details381 // for layout382 keepService: true383 }));384 } catch(e) {385 console.log("getScreen.newBrowser", e);386 fs.writeFileSync('grader.error', JSON.stringify({err:e, msg:e+''}));387 }388 389 // wait until the key is set390 await hasKey('screen');391 // kill the browser __ it has served its purpose, honorably and nobly392 await close(UI); 393 394 screen = load('screen');395 }396 console.log({screen});397 return screen;398 }399// control functions400 async function send(command, params, UI = App.UI) {401 return await UI.send(command, params);402 }403 async function on(eventName, handler, UI = App.UI) {404 return await UI.on(eventName, handler);405 }406 function off() {407 throw new TypeError(`off is not implemented yet...`);408 }409// util part i: KV functions (keys are strings)410 function save(key, value) {411 DEBUG && console.log({save:{key,value}});412 key += '';413 if ( typeof value == "object" ) {414 // do a pseudo merge415 let newValue;416 if ( Array.isArray(value) ) {417 const existing = KV[key] || [];418 if ( Array.isArray(existing) ) {419 newValue = [...existing, ...value];420 } else if ( typeof existing == "object" ) {421 value.forEach((v,i) => {422 existing[i] = v;423 });424 newValue = existing;425 } else {426 newValue = value;427 }428 } else {429 const existing = KV[key] || {};430 newValue = Object.assign(existing, value);431 }432 KV[key] = newValue;433 } else {434 KV[key] = value;435 }436 // run any listeners waiting for this key to be set437 let listeners = HasListeners.get(key);438 if ( listeners ) {439 HasListeners.delete(key);440 listeners.forEach(res => {441 // execute each without a stack442 setTimeout(() => res(true), 0);443 });444 }445 }446 function load(key) {447 key += '';448 return KV[key];449 }450 function del(key) {451 key += '';452 delete KV[key];453 }454 // returns a promise that resolves to true when the key is set455 async function hasKey(key) {456 key += '';457 let resolve;458 const pr = new Promise(res => resolve = res);459 let hasKey = false;460 hasKey = Object.prototype.hasOwnProperty.call(KV, key);461 if ( hasKey ) {462 return resolve(true);463 } else {464 let listeners = HasListeners.get(key);465 if ( ! listeners ) {466 listeners = [];467 HasListeners.set(key, listeners);468 }469 // these listeners will be called by save once key is set470 listeners.push(resolve);471 }472 return pr;473 }474// service only functions (not available over the API bridge to UI)475 function publishAPI(apiRoot, slotName) {476 // apiRoot is an object with properties that enumerate all the functions of that API477 // e.g. if your API is "sendEmail", "checkReplies", your apiRoot is478 // {sendEmail, checkReplies}479 // you can overwrite built-in APIs (like uitl, ui, control and window)480 // but we throw if you try to overwrite those APIs you publish481 Object.defineProperty(API, slotName, {482 get: () => apiRoot,483 set() {484 throw new TypeError(`API slot ${slotName} is already present and cannot be overwritten.`);485 }486 });487 }488 function getUI(name) {489 if ( ! App ) {490 throw new TypeError(`Cannot call getUI when App does not exist.`);491 }492 if ( App.uis.has(name) ) {493 return App.uis.get(name);494 } else {495 throw new TypeError(`UI with name ${name} does not exist.`);496 }497 }498 function getApp() {499 if ( ! App ) {500 throw new TypeError(`Cannot call getApp when App does not exist.`);501 }502 return App;503 }...

Full Screen

Full Screen

main.js

Source:main.js Github

copy

Full Screen

...36 webPreferences: {37 nodeIntegration: true,38 },39 })40 setWindowBounds()41 setWindowBounds()42 let indexPath43 if (isDev && process.argv.indexOf('--noDevServer') === -1) {44 indexPath = url.format({45 protocol: 'http:',46 host: 'localhost:8080',47 pathname: 'index.html',48 slashes: true,49 })50 } else {51 indexPath = url.format({52 protocol: 'file:',53 pathname: path.join(__dirname, 'dist', 'index.html'),54 slashes: true,55 })56 }57 mainWindow.loadURL(indexPath)58 // Don't show until we are ready and loaded59 mainWindow.once('ready-to-show', () => {60 mainWindow.show()61 // Open devtools if dev62 if (isDev) {63 const {64 default: installExtension,65 REACT_DEVELOPER_TOOLS,66 } = require('electron-devtools-installer')67 installExtension(REACT_DEVELOPER_TOOLS).catch((err) =>68 console.log('Error loading React DevTools: ', err)69 )70 mainWindow.webContents.openDevTools()71 }72 })73 mainWindow.on('closed', () => (mainWindow = null))74}75function createTray() {76 // Create Tray77 tray = new Tray(`${__dirname}/assets/icons/windows-icon@2x.png`)78 // set Titel79 tray.setToolTip('SysInfo')80 // Toggle hide81 tray.on('click', (e) => {82 if (mainWindow.isVisible()) {83 mainWindow.hide()84 } else {85 mainWindow.show()86 }87 })88 tray.on('right-click', () => {89 // create close-menu90 const template = [{ role: 'quit' }]91 const menu = Menu.buildFromTemplate(template)92 tray.popUpContextMenu(menu)93 })94}95function setWindowBounds(choosenScreen = storeSettinsgs.settings.screen) {96 // Set mainWindow on top-right97 const { width: windowWidth, height: windowHeight } = mainWindow.getBounds();98 let window = screen.getPrimaryDisplay()99 if (storeSettinsgs && storeSettinsgs.windows === screen.getAllDisplays().length) {100 let tempWd = screen.getAllDisplays();101 window = tempWd[choosenScreen];102 }103 mainWindow.setBounds({104 x: window.workArea.x + (window.workArea.width - windowWidth),105 y: window.workArea.y,106 width: windowWidth,107 height: windowHeight108 })109}110app.on('ready', () => {111 createMainWindow()112 createTray()113})114app.on('window-all-closed', () => {115 if (process.platform !== 'darwin') {116 app.quit()117 }118})119app.on('activate', () => {120 if (mainWindow === null) {121 createMainWindow()122 }123})124// IPC-Calls125ipcMain.on('infos:getStatic', async () => {126 let infos = await getStaticInfos()127 mainWindow.webContents.send('infos:receiveStatic', infos)128})129ipcMain.on('infos:getDynamicDashboard', async () => {130 let infos = await getDynamicDashboard()131 mainWindow.webContents.send('infos:receiveDynamicDashboard', infos)132})133ipcMain.on('settings:get', () => {134 mainWindow.webContents.send('settings:receive', { ...store.get('settings'), 'windows': screen.getAllDisplays().length })135})136ipcMain.on('settings:save', (sender, data) => {137 store.set('settings', data)138 mainWindow.setOpacity(parseFloat(data.settings.opacity))139 mainWindow.isAlwaysOnTop(parseBooleans(data.settings.isAlwaysOnTop))140 setWindowBounds(data.settings.screen)141 setWindowBounds(data.settings.screen)142})143// Stop error...

Full Screen

Full Screen

electronUtil.js

Source:electronUtil.js Github

copy

Full Screen

1const { INIT_WINDOW_STYLE } = require('../../com-constant')2// const { doubced } = require('../../com-function')3function setWindowBounds(mainWindow, data) {4 mainWindow.setSize(data.width, data.height)5 if (data.x === data.y && data.x === 'center') {6 mainWindow.center()7 } else if (data.x != null && data.y != null) {8 mainWindow.setPosition(data.x, data.y)9 }10}11exports.setWindowBounds = setWindowBounds12exports.setMoyuModeData = function (mainWin, data = {}) {13 setWindowBounds(mainWin, data)14 mainWin.setAlwaysOnTop(data.isTop, 'screen-saver')15 mainWin.setIgnoreMouseEvents(data.isTransparent)16}17function winScreen(win) {18 let isFullScreen = false19 let prevxy = {20 // width:21 ...INIT_WINDOW_STYLE,22 x: 'center',23 y: 'center',24 }25 win.on('enter-full-screen', () => {26 // isFullScreen = true27 setPrevdata()28 })29 /* const doubcedMoved = doubced(setPrevxy, 500)30 win.on('move', () => {31 // isFullScreen = true32 doubcedMoved()33 }) */34 function setPrevxy() {35 const [x, y] = win.getPosition()36 prevxy.x = x37 prevxy.y = y38 console.log('setPrevxy', prevxy)39 }40 function getPosi() {41 var data = win.getBounds()42 const [x, y] = win.getPosition()43 data.x = x44 data.y = y45 return data46 }47 function setPrevdata() {48 prevxy = getPosi()49 console.log('setPrevdata', prevxy)50 return prevxy51 }52 /* win.on('blur', (a, b) => {53 console.log('blur', win.getBounds())54 }) */55 function toggleAddSize(data) {56 let isAdd = false57 return {58 isAdded() {59 return isAdd60 },61 hide() {62 if (!isAdd) {63 return64 }65 isAdd = false66 const dat = getPosi()67 // restore()68 setWindowBounds(win, {69 width: dat.width - (data.width || 0),70 height: dat.height - (data.height || 0),71 })72 },73 show(letd) {74 if (isAdd) {75 return76 }77 isAdd = true78 data = letd || data79 const { width, height } = setPrevdata()80 setWindowBounds(win, {81 width: width + (data.width || 0),82 height: height + (data.height || 0),83 })84 },85 toggle(data) {86 if (isAdd) {87 this.hide()88 } else {89 this.show(data)90 }91 return isAdd92 },93 }94 }95 function toFullScreen() {96 // 透明化后,这里获取的是全屏的信息97 // console.log(win.getBounds())98 /* prevxy = win.getBounds()99 const [x, y] = win.getPosition()100 prevxy.x = x101 prevxy.y = y */102 win.setFullScreen(true)103 isFullScreen = true104 // console.log('prevxy', prevxy)105 }106 function exitFullScreen() {107 // console.log('退出全屏', isFullScreen)108 if (isFullScreen) {109 isFullScreen = false110 restore()111 }112 }113 function restore() {114 setWindowBounds(win, prevxy)115 }116 return {117 setPrevdata,118 toggleAddSize,119 setfs(f) {120 isFullScreen = f121 },122 isFullScreen() {123 return isFullScreen124 },125 toFullScreen,126 exitFullScreen,127 restore,128 }...

Full Screen

Full Screen

NavigationLayout.js

Source:NavigationLayout.js Github

copy

Full Screen

...13// win.setResizable(true);14// win.setMaximizable(true);15// win.setFullScreenable(true);16// win.setMinimumSize(size.width, size.height);17// setWindowBounds(size, { animated: true });18// win.center();19// };20const styles = theme => ({21 content: {22 flexGrow: 1,23 // backgroundColor: theme.palette.background.default,24 backgroundColor: '#fff',25 // padding: theme.spacing.unit * 3,26 marginLeft: 72,27 // marginTop: 64,28 minHeight: '100%'29 },30 dicoDrawer: {31 color: theme.drawer.color,...

Full Screen

Full Screen

AppTray.js

Source:AppTray.js Github

copy

Full Screen

...31 } else {32 y = y + 30;33 }34 }35 this.setWindowBounds(x, y);36 };37 setWindowBounds = (x, y) => {38 const { height, width } = this.appWindow.getBounds();39 const xCoord = Math.floor(x - width / 2);40 if (y <= 50) {41 this.appWindow.setContentBounds({42 x: xCoord,43 y: y,44 height,45 width,46 });47 } else {48 this.appWindow.setContentBounds({49 x: xCoord,...

Full Screen

Full Screen

browserHandler.js

Source:browserHandler.js Github

copy

Full Screen

...22 }23};24const setWindowBounds = async (targetId, height, width) => {25 const { windowId } = await _browser.getWindowForTarget({ targetId });26 await _browser.setWindowBounds({27 bounds: { height, width },28 windowId,29 });30};31const clearPermissionOverrides = async () => {32 await _browser.resetPermissions();33};...

Full Screen

Full Screen

txnCheck.js

Source:txnCheck.js Github

copy

Full Screen

1const puppeteer = require("puppeteer-extra");2const StealthPlugin = require("puppeteer-extra-plugin-stealth");3puppeteer.use(StealthPlugin());4const AdblockerPlugin = require("puppeteer-extra-plugin-adblocker");5puppeteer.use(AdblockerPlugin({ blockTrackers: true }));6async function txnCheck(url) {7 return new Promise(async (resolve, reject) => {8 const browser = await puppeteer.launch({9 headless: false,10 });11 const page = await browser.newPage();12 const session = await page.target().createCDPSession();13 const {windowId} = await session.send('Browser.getWindowForTarget');14 await session.send('Browser.setWindowBounds', {windowId, bounds: {windowState: 'minimized'}});15 await page.goto(url);16 await page.waitForSelector("#ContentPlaceHolder1_maintable");17 18 try {19 let cardText = await page.$eval("#ContentPlaceHolder1_maintable .row:nth-child(4) div:nth-child(2)", (text) => text.textContent);20 await browser.close();21 resolve(cardText);22 } catch (error) {23 await browser.close();24 resolve("Unknown");25 }26 });27}...

Full Screen

Full Screen

util.js

Source:util.js Github

copy

Full Screen

1async function minimize(page) {2 const session = await page.target().createCDPSession();3 const goods = await session.send("Browser.getWindowForTarget");4 const { windowId } = goods;5 await session.send("Browser.setWindowBounds", {6 windowId,7 bounds: { windowState: "minimized" },8 });9 10 return;11 }12 13async function maximize(page) {14 const session = await page.target().createCDPSession();15 const goods = await session.send("Browser.getWindowForTarget");16 const { windowId } = goods;17 await session.send("Browser.setWindowBounds", {18 windowId,19 bounds: { windowState: "normal" },20 });21 }22module.exports = {23 minimize,24 maximize...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const { width, height } = await page.evaluate(() => {7 return {8 }9 });10 console.log(width, height);11 await page.evaluate((width, height) => {12 return window.playwright.setWindowBounds({13 });14 }, width, height);15 const { width: newWidth, height: newHeight } = await page.evaluate(() => {16 return {17 }18 });19 console.log(newWidth, newHeight);20 await browser.close();21})();22const { chromium } = require('playwright');23const path = require('path');24(async () => {25 const browser = await chromium.launch();26 const context = await browser.newContext();27 const page = await context.newPage();28 await page.evaluate(() => {29 return window.playwright.setWindowBounds({30 });31 });32 await browser.close();33})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 const currentWindowBounds = await page._delegate._pageProxy._session.send('Browser.getWindowForTarget');7 console.log(currentWindowBounds);8 const newBounds = {9 bounds: {10 },11 };12 await page._delegate._pageProxy._session.send('Browser.setWindowBounds', newBounds);13 await page.screenshot({ path: 'screenshot.png' });14 await browser.close();15})();16{17 "bounds": {18 },19}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({4 });5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.setWindowBounds({ width: 800, height: 600 });8 await browser.close();9})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { setWindowBounds } = require('playwright/lib/server/chromium/crBrowser');2setWindowBounds.call(browser, { width: 1920, height: 1080, windowState: 'normal' });3const { setWindowBounds } = require('playwright/lib/server/chromium/crBrowser');4setWindowBounds.call(browser, { width: 1920, height: 1080, windowState: 'normal' });5const { setWindowBounds } = require('playwright/lib/server/chromium/crBrowser');6setWindowBounds.call(browser, { width: 1920, height: 1080, windowState: 'normal' });7const { setWindowBounds } = require('playwright/lib/server/chromium/crBrowser');8setWindowBounds.call(browser, { width: 1920, height: 1080, windowState: 'normal' });9const { setWindowBounds } = require('playwright/lib/server/chromium/crBrowser');10setWindowBounds.call(browser, { width: 1920, height: 1080, windowState: 'normal' });11const { setWindowBounds } = require('playwright/lib/server/chromium/crBrowser');12setWindowBounds.call(browser, { width: 1920, height: 1080, windowState: 'normal' });

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const fs = require('fs');3const path = require('path');4const { setWindowBounds } = require('playwright/lib/server/chromium/crBrowser');5(async () => {6 const browser = await chromium.launch({ headless: false });7 const context = await browser.newContext();8 const page = await context.newPage();9 const browserServer = browser._browserServer;10 const browserContext = browser._defaultContext;11 const browserWindow = browserContext._browserWindow;12 await setWindowBounds(browserWindow, {13 position: { x: 0, y: 0 },14 size: { width: 1920, height: 1080 },15 });16 await page.screenshot({ path: 'full-page.png' });17 await browser.close();18})();19at Object.setWindowBounds (/home/kiran/automation/node_modules/playwright/lib/server/chromium/crBrowser.js:36:11)20at processTicksAndRejections (internal/process/task_queues.js:97:5)21at async Object.exports.setWindowBounds (/home/kiran/automation/node_modules/playwright/lib/utils/utils.js:101:26)22at async Object.exports.setWindowBounds (/home/kiran/automation/node_modules/playwright/lib/utils/utils.js:112:16)23const { chromium } = require('playwright');24const fs = require('fs');25const path = require('path');26const { getWindowBounds } = require('playwright/lib/server/chromium/crBrowser');27(async () => {28 const browser = await chromium.launch({ headless: false });29 const context = await browser.newContext();30 const page = await context.newPage();31 const browserServer = browser._browserServer;32 const browserContext = browser._defaultContext;33 const browserWindow = browserContext._browserWindow;

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const { setWindowBounds } = require('playwright/lib/server/chromium/crBrowser');3const { debug } = require('playwright/lib/utils/debug');4(async () => {5 const browser = await chromium.launch({6 });7 const context = await browser.newContext();8 const page = await context.newPage();9 const windowHandle = await page.evaluate(() => window);10 const windowBounds = await page.evaluate(() => {11 return {12 };13 });14 await setWindowBounds.call(windowHandle, windowBounds);15 await page.screenshot({ path: 'google.png' });16 await browser.close();17})();18const { chromium } = require('playwright');19const { setWindowBounds } = require('playwright/lib/server/chromium/crBrowser');20const { debug } = require('playwright/lib/utils/debug');21(async () => {22 const browser = await chromium.launch({23 });24 const context = await browser.newContext();25 const page = await context.newPage();26 const windowHandle = await page.evaluate(() => window);27 const windowBounds = await page.evaluate(() => {28 return {29 };30 });31 await setWindowBounds.call(windowHandle, windowBounds);32 await page.screenshot({ path: 'google.png' });33 await browser.close();34})();

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful