How to use _onClosed method in Puppeteer

Best JavaScript code snippet using puppeteer

app_folder.js

Source:app_folder.js Github

copy

Full Screen

1/*2 * Copyright 2006-2008 Appcelerator, Inc.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License. 15 */16Appcelerator.Widget.Folder =17{18 modulePath:null,19 20 setPath: function(path)21 {22 this.modulePath = path;23 },24 getName: function()25 {26 return 'appcelerator folder';27 },28 getDescription: function()29 {30 return 'folder widget';31 },32 getVersion: function()33 {34 return '1.0.1';35 },36 getSpecVersion: function()37 {38 return 1.0;39 },40 getAuthor: function()41 {42 return 'Jeff Haynie';43 },44 getModuleURL: function ()45 {46 return 'http://www.appcelerator.org';47 },48 isWidget: function ()49 {50 return true;51 },52 getWidgetName: function()53 {54 return 'app:folder';55 },56 getAttributes: function()57 {58 return [];59 },60 getActions: function()61 {62 return ['openAll','closeAll', 'selectItem','open','close'];63 },64 openAll: function(id,parameterMap,data,scope,version)65 {66 var nodes = $(id).childNodes;67 68 for (var c=0;c<nodes.length;c++)69 {70 nodes[c]._onopened();71 }72 },73 closeAll: function(id,parameterMap,data,scope,version)74 {75 var nodes = $(id).childNodes;76 for (var c=0;c<nodes.length;c++)77 {78 nodes[c]._onclosed();79 }80 },81 close: function(id,parameterMap,data,scope,version,customActionArguments)82 {83 var folderIdx = Object.getNestedProperty(customActionArguments[0],'value');84 folderIdx = parseInt(folderIdx)*2;85 var folderId = id + '_folder_' + folderIdx;86 $(folderId)._onclosed();87 },88 open: function(id,parameterMap,data,scope,version,customActionArguments)89 {90 var folderIdx = Object.getNestedProperty(customActionArguments[0],'value');91 folderIdx = parseInt(folderIdx)*2;92 var folderId = id + '_folder_' + folderIdx;93 $(folderId)._onopened();94 },95 selectItem: function(id,parameterMap,data,scope,version,customActionArguments)96 {97 // the args come in as an array of the form: [{key:..,value:...},{key:..,value:...}] so we iterate over the array to account for order differences98 var folderIdx;99 var nodeIdx; 100 101 for (var i = 0; i < customActionArguments.length; i++)102 {103 if (Object.getNestedProperty(customActionArguments[i],'key') == 'folder')104 {105 folderIdx = Object.getNestedProperty(customActionArguments[i],'value');106 } else if (Object.getNestedProperty(customActionArguments[i],'key') == 'item')107 {108 nodeIdx = Object.getNestedProperty(customActionArguments[i],'value'); 109 }110 }111 112 //Folder ids are even numbers for whatever reason so map the user's folder index to its folder number113 folderIdx = parseInt(folderIdx)*2;114 var folderId = id + '_folder_' + folderIdx;115 var nodeId = id + '_folder_' + folderIdx + '_child_' + nodeIdx;116 $(folderId)._onopened();117 $(nodeId)._onopened();118 },119 getChildNodes: function() {120 var T = Appcelerator.Types;121 122 var folderItemAttributes = [{123 name: 'open',124 type: T.messageReceive,125 description: 'A condition which will trigger the item to be opened'126 }, {127 name: 'onopen',128 type: T.messageSend,129 description: ''130 }, {131 name: 'onclose',132 type: T.messageSend,133 description: ''134 }, {135 name: 'opened_icon',136 optional: true,137 type: T.pathOrUrl138 }, {139 name: 'closed_icon',140 optional: true,141 type: T.pathOrUrl142 }];143 144 return [{145 name: 'folder',146 attributes: folderItemAttributes,147 childNodes: [{148 name: 'item',149 attributes: folderItemAttributes150 }]151 }];152 },153 compileWidget: function (params)154 {155 var itemCloser = function(exclude)156 {157 params['itemnodes'].each(function(child){if (exclude!=child && $(child).opened) $(child)._onclosed();});158 }159 var closeChildren = function(parentid, childid)160 {161 $A($(parentid+'_children').childNodes).findAll(function(n){return n.nodeType==1;}).each(function(n){if (n.id!=childid) $(n.id)._onclosed();});162 }163 164 var nodes = params['nodes'];165 166 for (var c=0;c<nodes.length;c++)167 {168 (function(){169 var node = nodes[c];170 if (node.nodeType == 1 && node.nodeName.toLowerCase() == 'folder')171 {172 var parentid = node._parentid;173 var parentnode = $(parentid);174 175 node._children.each(function(child,b)176 {177 var childid = child._childid;178 var open = child.getAttribute('open');179 var openaction = child.getAttribute('onopen');180 var closeaction = child.getAttribute('onclose'); 181 182 if (openaction)183 {184 openaction = Appcelerator.Compiler.makeAction(childid,openaction);185 }186 if (closeaction)187 {188 closeaction = Appcelerator.Compiler.makeAction(childid,closeaction);189 }190 191 if (open)192 {193 var scriptcode = "$('"+parentid+"')._onopened(); $('"+childid+"')._onopened();";194 Appcelerator.Compiler.handleCondition(child, open, 'function['+scriptcode+']', null, 0, null);195 }196 $(childid)._onopened = function() 197 { 198 if (!$(childid).opened) 199 { 200 itemCloser(childid); 201 Element.removeClassName(childid+'_item','closed');202 Element.addClassName(childid+'_item','opened');203 $(childid).opened=true;204 Element.hide(childid+'_closed');205 Element.show(childid+'_opened');206 closeChildren(parentid, childid);207 if (openaction)208 {209 openaction();210 }211 }212 };213 214 $(childid)._onclosed = function()215 {216 if ($(childid).opened)217 {218 $(childid).opened=false; 219 Element.removeClassName(childid+'_item','open');220 Element.addClassName(childid+'_item','closed');221 Element.hide(childid+'_opened'); 222 Element.show(childid+'_closed');223 if (closeaction)224 {225 closeaction();226 }227 }228 };229 230 $(childid+'_closed').onclick = function()231 {232 $(childid)._onopened();233 };234 235 $(childid+'_opened').onclick = function()236 {237 $(childid)._onclosed();238 };239 240 $(childid).onclick = function(e)241 {242 e = Event.getEvent(e);243 e.stop();244 245 if ($(childid).opened)246 {247 $(childid)._onclosed(); 248 }249 else250 {251 $(childid)._onopened();252 }253 };254 255 $(childid)._onclosed();256 });257 258 $(parentid+'_closed').onclick = function()259 {260 parentnode.opened=true;261 Element.hide(parentid+'_closed');262 Element.show(parentid+'_opened');263 Element.toggle(parentid+'_children');264 };265 266 $(parentid+'_opened').onclick = function()267 {268 parentnode.opened=false;269 Element.hide(parentid+'_opened');270 Element.show(parentid+'_closed');271 Element.toggle(parentid+'_children');272 }273 274 parentnode._onopened = function()275 {276 parentnode.opened=true;277 Element.hide(parentid+'_closed');278 Element.show(parentid+'_opened');279 Element.show(parentid+'_children'); 280 closeChildren(parentid, null);281 };282 283 parentnode._onclosed = function()284 {285 parentnode.opened=false;286 Element.show(parentid+'_closed');287 Element.hide(parentid+'_opened');288 Element.hide(parentid+'_children'); 289 closeChildren(parentid, null); 290 }291 292 parentnode.onclick = function(e)293 {294 e=Event.getEvent(e);295 e.stop();296 if (!parentnode.opened)297 { 298 parentnode._onopened();299 } 300 else301 { 302 parentnode._onclosed();303 }304 };305 }306 })();307 }308 },309 buildWidget: function(element, parameters)310 {311 var html = '';312 var x = 0;313 var id = element.id;314 var itemnodes = [];315 316 if (Appcelerator.Browser.isIE)317 {318 // NOTE: in IE, you have to append with namespace319 var newhtml = element.innerHTML;320 newhtml = newhtml.replace(/<FOLDER/g,'<APP:FOLDER').replace(/\/FOLDER>/g,'/APP:FOLDER>');321 newhtml = newhtml.replace(/<ITEM/g,'<APP:ITEM').replace(/\/ITEM>/g,'/APP:ITEM>');322 element.innerHTML = newhtml;323 }324 325 for (var c=0;c<element.childNodes.length;c++)326 {327 var node = element.childNodes[c];328 if (node.nodeType == 1 && node.nodeName.toLowerCase() == 'folder')329 {330 var folder_opened_icon = node.getAttribute('opened_icon') || Appcelerator.Widget.Folder.modulePath + 'images/folder_opened.png';331 var folder_closed_icon = node.getAttribute('closed_icon') || Appcelerator.Widget.Folder.modulePath + 'images/folder_closed.png';332 var parentid = id+"_folder_"+ (x++);333 node._parentid = parentid;334 html+='<div id="'+parentid+'">';335 html+='<div class="folder" id="'+parentid+'_folder"><img class="folder_image" src="'+folder_closed_icon+'" id="'+parentid+'_closed"/>';336 html+='<img class="folder_image" src="'+folder_opened_icon+'" id="'+parentid+'_opened" style="display:none"/>';337 html+='<span class="folder_name" id="'+parentid+'_name">'+node.getAttribute('name')+'</span></div>';338 html+='<div class="folder_children" id="'+parentid+'_children" style="display:none">';339 var children = $A(node.childNodes).findAll(function(n){ return n.nodeType == 1 && n.nodeName.toLowerCase()=='item'; });340 node._children = children;341 var childcloser='';342 children.each(function(child,b)343 {344 var item_open_icon = child.getAttribute('opened_icon') || Appcelerator.Widget.Folder.modulePath + 'images/item_opened.png';345 var item_closed_icon = child.getAttribute('closed_icon') || Appcelerator.Widget.Folder.modulePath + 'images/item_closed.png';346 var childid = parentid+'_child_'+b;347 child._childid = childid;348 html+='<div id="'+childid+'">';349 html+='<div id="'+childid+'_item" class="item"><img class="item_image" src="'+item_closed_icon+'" id="'+childid+'_closed"/>';350 html+='<img class="item_image" src="'+item_open_icon+'" id="'+childid+'_opened" style="display:none"/>';351 html+='<span class="item_name" id="'+childid+'_name">'+Appcelerator.Compiler.getHtml(child,true)+'</span>';352 html+='</div></div>';353 var openaction = child.getAttribute('onopen');354 var closeaction = child.getAttribute('onclose');355 if (openaction)356 {357 openaction = Appcelerator.Compiler.makeAction(childid,openaction) +";";358 }359 if (closeaction)360 {361 closeaction = Appcelerator.Compiler.makeAction(childid,closeaction) + ";";362 }363 itemnodes.push(childid);364 });365 html+='</div></div>';366 x++;367 }368 }369 370 parameters['nodes'] = element.childNodes;371 parameters['itemnodes'] = itemnodes;372 373 return {374 'position' : Appcelerator.Compiler.POSITION_REPLACE,375 'presentation' : html,376 'compile' : true377 };378 }379};380Appcelerator.Core.loadModuleCSS('app:folder','folder.css');...

Full Screen

Full Screen

window.js

Source:window.js Github

copy

Full Screen

...185 } else {186 // Let the window close as usual187 }188 }189 _onClosed(/* event */) {190 this._removeListeners();191 this.emit("closed", { window: this });192 }193 _onDirty(event, message) {194 if (event.sender === this.browserWindow.webContents) {195 console.log("Dirty event for window " + this.id, message);196 this.isDirty = message.isDirty;197 this._updateTitle();198 }199 }200 _onSAR(event, message) {201 if (event.sender === this.browserWindow.webContents) {202 this.emit("_SAR", message);203 }204 }205 _onShowMessageBox(event, message) {206 if (event.sender === this.browserWindow.webContents) {207 electron.dialog.showMessageBox(message);208 }209 }210 _sendMessage(name, message) {211 this.browserWindow.webContents.send(name, message);212 }213 _sendAndReceive(name, message, next) {214 let id = globalCounter++;215 let _next = (data) => {216 if (data.id === id) {217 this.removeListener("_SAR", _next);218 next(data.response);219 }220 };221 this.on("_SAR", _next);222 this.browserWindow.webContents.send("_SAR", { id, name, message });223 }224}225class CustomWindowManager {226 constructor() {227 this.windows = [];228 this._onClosed$bound = this._onClosed.bind(this);229 }230 create(filePath) {231 let window = new CustomWindow(filePath);232 window.on("closed", this._onClosed$bound);233 this.windows.push(window);234 return window;235 }236 getByBrowserWindow(browserWindow) {237 for (let window of this.windows) {238 if (window.browserWindow === browserWindow) {239 return window;240 }241 }242 return null;243 }244 getByPath(filePath) {245 for (let window of this.windows) {246 if (window.path === filePath) {247 return window;248 }249 }250 return null;251 }252 count() {253 return this.windows.length;254 }255 _onClosed(message) {256 let idx = this.windows.indexOf(message.window);257 let window = this.windows[idx];258 window.removeListener("closed", this._onClosed$bound);259 this.windows.splice(idx, 1);260 }261}...

Full Screen

Full Screen

AbstractWindow.spec.js

Source:AbstractWindow.spec.js Github

copy

Full Screen

...61 SingleEventTestee = class SingleEventTestee extends Testee {62 constructor() {63 super();64 }65 _onClosed() {66 this.spies['_onClosed'].apply(this, arguments);67 }68 };69 sinon.stub(include, 'resolve').returns('modules/testee/templates/testee');70 BrowserWindow = require('electron').BrowserWindow;71 BrowserWindow.___spy.reset();72 });73 afterEach(() => {74 include.resolve.restore();75 });76 it('should create a new BrowserWindow using the proper template and send the context information', () => {77 expect(BrowserWindow.___spy.called).toBe(false);78 var testee = new Testee();79 // uses BrowserWindow...

Full Screen

Full Screen

modal.js

Source:modal.js Github

copy

Full Screen

1const Nanocomponent = require('nanocomponent')2const morph = require('nanomorph')3const html = require('choo/html')4const css = require('sheetify')5const omit = require('lodash/omit')6const modalClass = css`7 @keyframes tdFadeBackgroundIn {8 0% { background-color: rgba(0,0,0,0); }9 100% { background-color: rgba(0,0,0,0.8); }10 }11 @keyframes tdFadeBackgroundOut {12 0% { background-color: rgba(0,0,0,0.8); }13 100% { background-color: rgba(0,0,0,0); }14 }15 :host {16 font-family: system-ui, -apple-system, BlinkMacSystemFont,17 "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell",18 "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;19 }20 :host(.open) {21 z-index: 9999;22 position: absolute;23 top: 0;24 bottom: 0;25 width: 100%;26 display: flex;27 align-items: center;28 justify-content: center;29 max-height: 100%;30 overflow-y: scroll;31 animation-name: tdFadeBackgroundIn;32 animation-duration: .3s;33 animation-fill-mode: both;34 }35 :host(.closing) {36 animation-name: tdFadeBackgroundOut;37 pointer-events: none;38 }39 :host > div {40 position: relative;41 }42 :host > div:focus {43 outline: none;44 }45`46module.exports = ModalPortal47function ModalPortal () {48 if (!(this instanceof ModalPortal)) return new ModalPortal()49 this.portal = html`<div></div>`50 this.modal = new Modal()51 document.body.appendChild(this.portal)52}53ModalPortal.prototype.render = function (props) {54 morph(this.portal, this.modal.render(props))55 return null56}57function Modal () {58 if (!(this instanceof Modal)) return new Modal()59 this.state = {}60 this._onOpened = this._onOpened.bind(this)61 this._onClosed = this._onClosed.bind(this)62 this._onClick = this._onClick.bind(this)63 this._onKeyDown = this._onKeyDown.bind(this)64 Nanocomponent.call(this)65}66const proto = Modal.prototype = Object.create(Nanocomponent.prototype)67proto.createElement = function (props) {68 this.props = props69 // Don't remove from the DOM while it's still closing70 const open = props.open || this.state.closing71 const childProps = omit(props, ['render', 'open'])72 return html`73 <div class='${modalClass} ${open ? 'open' : ''}' onclick=${this._onClick}>74 ${open ? html`<div onkeydown=${this._onKeyDown} tabindex='-1'>${props.render(childProps)}</div>` : null}75 </div>76 `77}78proto.load = function (el) {79 el.childNodes[0] && el.childNodes[0].focus()80}81proto.update = function (nextProps) {82 // Wasn't open, now it is83 if (!this.props.open && nextProps.open) {84 this.state.opening = true85 this.state.closing = false86 }87 // Was open, now it's closed88 if (this.props.open && !nextProps.open) this.state.closing = true89 return true90}91proto.afterupdate = function (el) {92 el.childNodes[0] && el.childNodes[0].focus()93 if (this.state.opening) {94 el.classList.add('open', 'opening')95 el.addEventListener('animationend', this._onOpened, false)96 }97 if (this.state.closing) {98 this.state.opening = false99 el.classList.remove('opening')100 el.classList.add('closing')101 el.removeEventListener('animationend', this._onOpened)102 el.addEventListener('animationend', this._onClosed, false)103 }104}105proto._onOpened = function (e) {106 this.element.removeEventListener('animationend', this._onOpened)107 this.state.opening = false108 this.element.classList.remove('opening')109}110proto._onClosed = function (e) {111 if (e.target !== this.element) return112 e.target.removeEventListener('animationend', this._onClosed)113 this.element.classList.remove('open')114 this.state.closing = false115 this.rerender()116}117proto._onClick = function (e) {118 if (e.target !== this.element) return119 this.props.close()120}121proto._onKeyDown = function (e) {122 if (e.key === 'Escape') this.props.close()...

Full Screen

Full Screen

generic-list-view.js

Source:generic-list-view.js Github

copy

Full Screen

1var __extends = (this && this.__extends) || function (d, b) {2 for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];3 function __() { this.constructor = d; }4 __.prototype = b.prototype;5 d.prototype = new __();6};7var spacePen = require("atom-space-pen-views");8var _ = require('lodash');9var rx_1 = require("rx");10var GenericSelectListView = (function (_super) {11 __extends(GenericSelectListView, _super);12 function GenericSelectListView(messageText, _items, onConfirm, onCancel) {13 _super.call(this);14 this.messageText = messageText;15 this._items = _items;16 this.onConfirm = onConfirm;17 this.onCancel = onCancel;18 this._onClosed = new rx_1.AsyncSubject();19 this.keyBindings = null;20 }21 Object.defineProperty(GenericSelectListView.prototype, "onClosed", {22 get: function () { return this._onClosed; },23 enumerable: true,24 configurable: true25 });26 ;27 GenericSelectListView.content = function () {28 var _this = this;29 return this.div({}, function () {30 _this.p({31 outlet: 'message'32 }, '');33 spacePen.SelectListView.content.call(_this);34 });35 };36 GenericSelectListView.prototype.initialize = function () {37 spacePen.SelectListView.prototype.initialize.call(this);38 this.addClass('generic-list');39 this.message.text(this.messageText);40 return false;41 };42 GenericSelectListView.prototype.getFilterKey = function () {43 return 'displayName';44 };45 GenericSelectListView.prototype.cancelled = function () {46 this.onCancel();47 return this.hide();48 };49 GenericSelectListView.prototype.toggle = function () {50 if (this.panel && this.panel.isVisible()) {51 this.cancel();52 }53 else {54 this.show();55 }56 };57 GenericSelectListView.prototype.show = function () {58 if (this.panel == null) {59 this.panel = atom.workspace.addModalPanel({ item: this });60 }61 this.panel.show();62 this.storeFocusedElement();63 if (this.previouslyFocusedElement[0] && this.previouslyFocusedElement[0] !== document.body) {64 this.eventElement = this.previouslyFocusedElement[0];65 }66 else {67 this.eventElement = atom.views.getView(atom.workspace);68 }69 this.keyBindings = atom.keymaps.findKeyBindings({70 target: this.eventElement71 });72 // infer the generator somehow? based on the project information? store in the project system??73 var commands = _.sortBy(this._items, 'displayName');74 this.setItems(commands);75 this.focusFilterEditor();76 };77 GenericSelectListView.prototype.hide = function () {78 this._onClosed.onNext(true);79 this._onClosed.onCompleted();80 this.panel && this.panel.hide();81 this.panel.destroy();82 this.panel = null;83 };84 GenericSelectListView.prototype.viewForItem = function (item) {85 var keyBindings = this.keyBindings;86 return spacePen.$$(function () {87 var _this = this;88 return this.li({89 "class": 'event',90 'data-event-name': item.name91 }, function () {92 return _this.span(item.displayName, {93 title: item.name94 });95 });96 });97 };98 GenericSelectListView.prototype.confirmed = function (item) {99 this.onConfirm(item.name);100 this.cancel();101 return null;102 };103 return GenericSelectListView;104})(spacePen.SelectListView);...

Full Screen

Full Screen

AmqpService.js

Source:AmqpService.js Github

copy

Full Screen

1/**2 * Copyright 2017–2018, LaborX PTY3 * Licensed under the AGPL Version 3 license.4 * @author Kirill Sergeev <cloudkserg11@gmail.com>5 */6const EventEmitter = require('events'),7 amqp = require('amqplib');89const TX_SEND = 'txSend';10/**11 * Class for subscribe on amqp events12 * from other middlewares13 * listen only selected messages14 *15 * @class AmqpServer16 * @extends {EventEmitter}17 */18class AmqpService extends EventEmitter19{20 /**21 *22 * constructor23 * @param {Object} config24 * options are:25 * url - url for rabbit26 * exchange - name exchange in rabbit27 * serviceName - service name of created queues for binding in rabbit28 *29 * @memberOf AmqpServer30 */31 constructor (config) {32 super();33 this.url = config.url;34 this.exchange = config.exchange;35 this.serviceName = config.serviceName;36 this.TX_SEND = TX_SEND;37 }383940 /**41 * function for start (connect to rabbit)42 *43 * @memberOf AmqpServer44 */45 async start () {46 this.amqpInstance = await amqp.connect(this.url);4748 this.channel = await this.amqpInstance.createChannel();49 await this.channel.assertExchange(this.exchange, 'topic', {durable: false});50 this._onClosed = () => {51 throw new Error('rabbitmq process has finished!');52 };53 this.channel.on('close', this._onClosed);5455 await this._addBind(this.serviceName);56 }575859 /**60 * function to subscribe to this channel61 *62 * @param {String} routing63 *64 * @memberOf AmqpServer65 */66 async _addBind (routing) {67 await this.channel.assertQueue(`${routing}`);68 await this.channel.bindQueue(`${routing}`, this.exchange, routing);69 this.channel.consume(`${routing}`, async (data) => {70 this.emit(this.TX_SEND, JSON.parse(data.content));71 this.channel.ack(data);72 });73 }7475 async _delBind (routing) {76 await this.channel.cancel(`${routing}`);77 }787980 async _publish (msg) {81 await this.channel.publish(this.exchange, this.serviceName, 82 new Buffer(JSON.stringify(msg)));83 }8485 async publishTx (blockchain, order, address) {86 const msg = {blockchain, order, address};8788 await this.channel.publish(this.exchange, this.serviceName, 89 new Buffer(JSON.stringify(msg)));90 }9192 async publishTxError (data, msg) {93 const routing = `${this.serviceName}.${data.blockchain}.${data.address}.${data.order}`;94 await this.channel.publish(this.exchange, routing, 95 new Buffer(JSON.stringify({ok: false, order: data.order, msg})));96 }9798 async publishTxOk (txModel) {99 const routing = `${this.serviceName}.${txModel.blockchain}.${txModel.address}.${txModel.order}`;100 await this.channel.publish(this.exchange, routing, 101 new Buffer(JSON.stringify({ok: true, hash: txModel.hash, order: txModel.order})));102 }103104105 /**106 * Function for close connection to rabbitmq107 *108 *109 * @memberOf AmqpServer110 */111 async close () {112 await this._delBind(this.serviceName);113 if (this._onClosed)114 this.channel.removeListener('close', this._onClosed);115 await this.amqpInstance.close();116 }117118}119 ...

Full Screen

Full Screen

lobby.js

Source:lobby.js Github

copy

Full Screen

...15 this._onInfo = undefined;16 this._onGameStart = undefined;17 this._onError = undefined;18 this._onUserAdd = undefined;19 this._onClosed && this._onClosed();20 }).bind(this);21 this._ws.onmessage = (function (evt) {22 let data = JSON.parse(evt.data);23 console.log('LobbyMessage: ', data);24 switch (data.type) {25 case 'Lobby Info':26 this._users = data.users;27 this._maxNumber = data.maxNumber;28 this._onInfo && this._onInfo(data);29 break;30 case 'UserAddedMessage':31 this._users.push(data.user);32 this._onUserAdd && this._onUserAdd(data);33 break;...

Full Screen

Full Screen

signalling.js

Source:signalling.js Github

copy

Full Screen

...74 let data = JSON.parse(event.data);75 let cb = this.cbMap.get(data.message);76 if (cb) cb(data);77 }78 _onClosed() {79 let cb = this.cbMap.get("closed");80 if (cb) cb();81 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch({headless: false});4 const page = await browser.newPage();5 await page.waitFor(3000);6 await page.close();7 await browser.close();8})();9const puppeteer = require('puppeteer');10(async () => {11 const browser = await puppeteer.launch({headless: false});12 browser.on('disconnected', () => console.log('Browser closed'));13 const page = await browser.newPage();14 await page.waitFor(3000);15 await page.close();16 await browser.close();17})();18The code above doesn't work. But if I remove the `await browser.close()` line, it works. I don't know why. I need to close the browser after the page is closed. How can I do this?19const puppeteer = require('puppeteer');20(async () => {21 const browser = await puppeteer.launch({headless: false});22 const page = await browser.newPage();23 await page.waitFor(3000);24 await page.close();25 browser.on('disconnected', () => console.log('Browser closed'));26 await browser.close();27})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page._client.send('Emulation.clearDeviceMetricsOverride');6 await browser.close();7})();8const puppeteer = require('puppeteer');9(async () => {10 const browser = await puppeteer.launch();11 const page = await browser.newPage();12 await page._client.send('Emulation.clearDeviceMetricsOverride');13 await browser.close();14})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch({ headless: false });4 const page = await browser.newPage();5 await browser.close();6})();7const puppeteer = require('puppeteer');8(async () => {9 const browser = await puppeteer.launch({ headless: false });10 const page = await browser.newPage();11 const client = await page.target().createCDPSession();12 await client.send('Network.enable');13 await client.send('Network.clearBrowserCookies');14 await client.send('Network.clearBrowserCache');15 await browser.close();16})();17const puppeteer = require('puppeteer');18(async () => {19 const browser = await puppeteer.launch({ headless: false });20 const page = await browser.newPage();21 await page.evaluate(() => {22 localStorage.setItem('name', 'puppeteer');23 });24 await browser.close();25})();26const puppeteer = require('puppeteer');27(async () => {28 const browser = await puppeteer.launch({ headless: false });29 const page = await browser.newPage();30 await page.evaluate(() => {31 localStorage.setItem('name', 'puppeteer');32 });33 await page.evaluate(() => {34 localStorage.setItem('name', 'puppeteer');35 });36 await browser.close();37})();38const puppeteer = require('puppeteer');39(async () => {40 const browser = await puppeteer.launch({ headless: false });41 const page = await browser.newPage();42 await page.evaluate(() => {43 localStorage.setItem('name', 'puppeteer');44 });45 await page.evaluate(() => {46 localStorage.setItem('name', 'puppeteer');47 });48 await browser.close();49})();50const puppeteer = require('puppeteer');51(async () => {52 const browser = await puppeteer.launch({

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer-extra');2const StealthPlugin = require('puppeteer-extra-plugin-stealth');3puppeteer.use(StealthPlugin());4const fs = require('fs');5async function run() {6 const browser = await puppeteer.launch();7 const page = await browser.newPage();8 await page.screenshot({ path: 'google.png' });9 await browser.close();10}11run();12const puppeteer = require('puppeteer');13const fs = require('fs');14async function run() {15 const browser = await puppeteer.launch();16 const page = await browser.newPage();17 await page.screenshot({ path: 'google.png' });18 await browser.close();19}20run();

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2const fs = require('fs');3const path = require('path');4const { promisify } = require('util');5const writeFile = promisify(fs.writeFile);6const readFile = promisify(fs.readFile);7const _onClosed = async function () {8 const browser = await puppeteer.launch({9 executablePath: 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe',10 });11 const page = await browser.newPage();12 await page.waitFor(5000);13 await page.close();14 await browser.close();15 console.log('Browser Closed');16}17_onClosed();18const puppeteer = require('puppeteer');19const fs = require('fs');20const path = require('path');21const { promisify } = require('util');22const writeFile = promisify(fs.writeFile);23const readFile = promisify(fs.readFile);24const _onCrashed = async function () {25 const browser = await puppeteer.launch({26 executablePath: 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe',27 });28 const page = await browser.newPage();29 await page.waitFor(5000);30 await page.crash();31 await browser.close();32 console.log('Browser Closed');33}34_onCrashed();35const puppeteer = require('puppeteer');36const fs = require('fs');37const path = require('path');38const { promisify } = require('util');39const writeFile = promisify(fs.writeFile);40const readFile = promisify(fs.readFile);41const _onDisconnected = async function () {42 const browser = await puppeteer.launch({43 executablePath: 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe',44 });

Full Screen

Using AI Code Generation

copy

Full Screen

1let browser = await puppeteer.launch({ headless: false });2let page = await browser.newPage();3await page.evaluate(() => {4 window.addEventListener('beforeunload', (event) => {5 console.log('beforeunload');6 });7 window.addEventListener('unload', (event) => {8 console.log('unload');9 });10});11await page.close();12await browser.close();13let browser = await puppeteer.launch({ headless: false });14let page = await browser.newPage();15await page.evaluate(() => {16 console.log('hello world');17});18await page.close();19await browser.close();20let browser = await puppeteer.launch({ headless: false });21let page = await browser.newPage();22await page.evaluate(() => {23 alert('hello world');24});25await page.close();26await browser.close();27let browser = await puppeteer.launch({ headless: false });28let page = await browser.newPage();29await page.evaluate(() => {30 document.addEventListener('DOMContentLoaded', (event) => {31 console.log('DOMContentLoaded');32 });33});34await page.close();35await browser.close();36let browser = await puppeteer.launch({ headless: false });37let page = await browser.newPage();38await page.evaluate(() => {39 window.addEventListener('error', (event) => {40 console.log('error', event);41 });42 throw new Error('error');43});44await page.close();45await browser.close();

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2const { PuppeteerBrowser } = require('testcafe-browser-provider-puppeteer');3const browser = new PuppeteerBrowser();4const launchOptions = {5};6let browserInstance = null;7 ._init()8 .then(() => browser._openBrowser(launchOptions))9 .then(instance => {10 browserInstance = instance;11 console.log('Browser opened');12 })13 .then(() => browser._newPage(browserInstance))14 .then(() => browser._closeBrowser(browserInstance))15 .then(() => browser._onClosed())16 .then(() => console.log('Browser closed'))17 .catch(err => console.error(err));18const puppeteer = require('puppeteer');19const { PuppeteerBrowser } = require('testcafe-browser-provider-puppeteer');20const browser = new PuppeteerBrowser();21const launchOptions = {22};23let browserInstance = null;24 ._init()25 .then(() => browser._openBrowser(launchOptions))26 .then(instance => {27 browserInstance = instance;28 console.log('Browser opened');29 })30 .then(() => browser._newPage(browserInstance))31 .then(page => {32 })33 .then(() => browser._getPageUrl(browserInstance))34 .then(url => {35 console.log('Page URL: ' + url);36 })37 .then(() => browser._closeBrowser(browserInstance))38 .then(() => browser._onClosed())39 .then(() => console.log('Browser closed'))40 .catch(err => console.error(err));41const puppeteer = require('puppeteer');42const { PuppeteerBrowser } = require('testcafe-browser-provider-puppeteer');43const browser = new PuppeteerBrowser();44const launchOptions = {45};

Full Screen

Using AI Code Generation

copy

Full Screen

1(async () => {2 const browser = await puppeteer.launch({headless: false, args: ['--no-sandbox']});3 const page = await browser.newPage();4 await page.screenshot({path: 'google.png'});5 await browser.close();6})();7 close() {8 this._onClosed();9 return this._connection.send('Browser.close').then(() => {});10 }11 _onClosed() {12 this._closed = true;13 this.emit(Launcher.Events.Disconnected, new Error('Browser closed.'));14 }15}16(async () => {17 const browser = await puppeteer.launch({headless: false, args: ['--no-sandbox']});18 const page = await browser.newPage();19 await page.screenshot({path: 'google.png'});20 try {21 await browser.close();22 } catch (e) {23 console.log(e)24 }25})();26(async () => {27 const browser = await puppeteer.launch({headless: false, args: ['--no-sandbox']});28 const page = await browser.newPage();29 await page.screenshot({path: 'google.png'});30 await browser.close().catch(e => console.log(e));31})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2const { expect } = require('chai');3const { _onClosed } = require('puppeteer/lib/Launcher');4describe('Test', () => {5 let browser;6 let page;7 before(async () => {8 browser = await puppeteer.launch();9 page = await browser.newPage();10 });11 after(async () => {12 await browser.close();13 });14 it('should open the browser and close it', async () => {15 expect(await page.title()).to.be.a('string');16 });17});18const puppeteer = require('puppeteer');19const { expect } = require('chai');20const { _onClosed } = require('puppeteer/lib/Launcher');21describe('Test', () => {22 let browser;23 let page;24 before(async () => {25 browser = await puppeteer.launch();26 page = await browser.newPage();27 });28 after(async () => {29 await _onClosed.call(browser);30 });31 it('should open the browser and close it', async () => {32 expect(await page.title()).to.be.a('string');33 });34});

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteerCrawler = new Apify.PuppeteerCrawler({2});3const proxyConfiguration = await Apify.createProxyConfiguration({4});5const puppeteerCrawler = new Apify.PuppeteerCrawler({6});7const proxyConfiguration = await Apify.createProxyConfiguration({8});9const puppeteerCrawler = new Apify.PuppeteerCrawler({10 launchPuppeteerFunction: async ({ proxyUrl }) => {11 const browser = await Apify.launchPuppeteer({12 });13 return browser;14 },15});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Puppeteer 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