Best JavaScript code snippet using puppeteer
stacktrace_test.js
Source:stacktrace_test.js
1// Copyright 2009 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14goog.provide('goog.testing.stacktraceTest');15goog.setTestOnly('goog.testing.stacktraceTest');16goog.require('goog.functions');17goog.require('goog.string');18goog.require('goog.testing.ExpectedFailures');19goog.require('goog.testing.PropertyReplacer');20goog.require('goog.testing.StrictMock');21goog.require('goog.testing.asserts');22goog.require('goog.testing.jsunit');23goog.require('goog.testing.stacktrace');24goog.require('goog.testing.stacktrace.Frame');25goog.require('goog.userAgent');26var stubs = new goog.testing.PropertyReplacer();27var expectedFailures;28function setUpPage() {29 expectedFailures = new goog.testing.ExpectedFailures();30}31function setUp() {32 stubs.set(goog.testing.stacktrace, 'isClosureInspectorActive_', function() {33 return false;34 });35}36function tearDown() {37 stubs.reset();38 expectedFailures.handleTearDown();39}40function testParseStackFrameInV8() {41 var frameString = ' at Error (unknown source)';42 var frame = goog.testing.stacktrace.parseStackFrame_(frameString);43 var expected = new goog.testing.stacktrace.Frame('', 'Error', '', '');44 assertObjectEquals('exception name only', expected, frame);45 frameString = ' at Object.assert (file:///.../asserts.js:29:10)';46 frame = goog.testing.stacktrace.parseStackFrame_(frameString);47 expected = new goog.testing.stacktrace.Frame(48 'Object', 'assert', '', 'file:///.../asserts.js:29:10');49 assertObjectEquals('context object + function name + url', expected, frame);50 frameString = ' at Object.x.y.z (/Users/bob/file.js:564:9)';51 frame = goog.testing.stacktrace.parseStackFrame_(frameString);52 expected = new goog.testing.stacktrace.Frame(53 'Object.x.y', 'z', '', '/Users/bob/file.js:564:9');54 assertObjectEquals(55 'nested context object + function name + url', expected, frame);56 frameString = ' at http://www.example.com/jsunit.js:117:13';57 frame = goog.testing.stacktrace.parseStackFrame_(frameString);58 expected = new goog.testing.stacktrace.Frame(59 '', '', '', 'http://www.example.com/jsunit.js:117:13');60 assertObjectEquals('url only', expected, frame);61 frameString = ' at [object Object].exec [as execute] (file:///foo)';62 frame = goog.testing.stacktrace.parseStackFrame_(frameString);63 expected = new goog.testing.stacktrace.Frame(64 '[object Object]', 'exec', 'execute', 'file:///foo');65 assertObjectEquals('function alias', expected, frame);66 frameString = ' at new Class (file:///foo)';67 frame = goog.testing.stacktrace.parseStackFrame_(frameString);68 expected =69 new goog.testing.stacktrace.Frame('', 'new Class', '', 'file:///foo');70 assertObjectEquals('constructor call', expected, frame);71 frameString = ' at new <anonymous> (file:///foo)';72 frame = goog.testing.stacktrace.parseStackFrame_(frameString);73 expected = new goog.testing.stacktrace.Frame(74 '', 'new <anonymous>', '', 'file:///foo');75 assertObjectEquals('anonymous constructor call', expected, frame);76 frameString = ' at Array.forEach (native)';77 frame = goog.testing.stacktrace.parseStackFrame_(frameString);78 expected = new goog.testing.stacktrace.Frame('Array', 'forEach', '', '');79 assertObjectEquals('native function call', expected, frame);80 frameString = ' at foo (eval at file://bar)';81 frame = goog.testing.stacktrace.parseStackFrame_(frameString);82 expected =83 new goog.testing.stacktrace.Frame('', 'foo', '', 'eval at file://bar');84 assertObjectEquals('eval', expected, frame);85 frameString = ' at foo.bar (closure/goog/foo.js:11:99)';86 frame = goog.testing.stacktrace.parseStackFrame_(frameString);87 expected = new goog.testing.stacktrace.Frame(88 'foo', 'bar', '', 'closure/goog/foo.js:11:99');89 assertObjectEquals('Path without schema', expected, frame);90 // In the Chrome console, execute: console.log(eval('Error().stack')).91 frameString =92 ' at eval (eval at <anonymous> (unknown source), <anonymous>:1:1)';93 frame = goog.testing.stacktrace.parseStackFrame_(frameString);94 expected = new goog.testing.stacktrace.Frame(95 '', 'eval', '', 'eval at <anonymous> (unknown source), <anonymous>:1:1');96 assertObjectEquals('nested eval', expected, frame);97}98function testParseStackFrameInOpera() {99 var frameString = '@';100 var frame = goog.testing.stacktrace.parseStackFrame_(frameString);101 var expected = new goog.testing.stacktrace.Frame('', '', '', '');102 assertObjectEquals('empty frame', expected, frame);103 frameString = '@javascript:console.log(Error().stack):1';104 frame = goog.testing.stacktrace.parseStackFrame_(frameString);105 expected = new goog.testing.stacktrace.Frame(106 '', '', '', 'javascript:console.log(Error().stack):1');107 assertObjectEquals('javascript path only', expected, frame);108 frameString = '@file:///foo:42';109 frame = goog.testing.stacktrace.parseStackFrame_(frameString);110 expected = new goog.testing.stacktrace.Frame('', '', '', 'file:///foo:42');111 assertObjectEquals('path only', expected, frame);112 // (function go() { throw Error() })()113 // var c = go; c()114 frameString = 'go([arguments not available])@';115 frame = goog.testing.stacktrace.parseStackFrame_(frameString);116 expected = new goog.testing.stacktrace.Frame('', 'go', '', '');117 assertObjectEquals('name and empty path', expected, frame);118 frameString = 'go([arguments not available])@file:///foo:42';119 frame = goog.testing.stacktrace.parseStackFrame_(frameString);120 expected = new goog.testing.stacktrace.Frame('', 'go', '', 'file:///foo:42');121 assertObjectEquals('name and path', expected, frame);122 // (function() { throw Error() })()123 frameString =124 '<anonymous function>([arguments not available])@file:///foo:42';125 frame = goog.testing.stacktrace.parseStackFrame_(frameString);126 expected = new goog.testing.stacktrace.Frame('', '', '', 'file:///foo:42');127 assertObjectEquals('anonymous function', expected, frame);128 // var b = {foo: function() { throw Error() }}129 frameString = '<anonymous function: foo>()@file:///foo:42';130 frame = goog.testing.stacktrace.parseStackFrame_(frameString);131 expected = new goog.testing.stacktrace.Frame('', 'foo', '', 'file:///foo:42');132 assertObjectEquals('object literal function', expected, frame);133 // var c = {}; c.foo = function() { throw Error() }134 frameString = '<anonymous function: c.foo>()@file:///foo:42';135 frame = goog.testing.stacktrace.parseStackFrame_(frameString);136 expected =137 new goog.testing.stacktrace.Frame('c', 'foo', '', 'file:///foo:42');138 assertObjectEquals('named object literal function', expected, frame);139 frameString = '<anonymous function: Foo.prototype.bar>()@';140 frame = goog.testing.stacktrace.parseStackFrame_(frameString);141 expected = new goog.testing.stacktrace.Frame('Foo.prototype', 'bar', '', '');142 assertObjectEquals('prototype function', expected, frame);143 frameString = '<anonymous function: goog.Foo.prototype.bar>()@';144 frame = goog.testing.stacktrace.parseStackFrame_(frameString);145 expected =146 new goog.testing.stacktrace.Frame('goog.Foo.prototype', 'bar', '', '');147 assertObjectEquals('namespaced prototype function', expected, frame);148}149// All test strings are parsed with the conventional and long150// frame algorithms.151function testParseStackFrameInFirefox() {152 var frameString = 'Error("Assertion failed")@:0';153 var frame = goog.testing.stacktrace.parseStackFrame_(frameString);154 var expected = new goog.testing.stacktrace.Frame('', 'Error', '', '');155 assertObjectEquals('function name + arguments', expected, frame);156 frameString = '()@file:///foo:42';157 frame = goog.testing.stacktrace.parseStackFrame_(frameString);158 expected = new goog.testing.stacktrace.Frame('', '', '', 'file:///foo:42');159 assertObjectEquals('anonymous function', expected, frame);160 frameString = '@javascript:alert(0)';161 frame = goog.testing.stacktrace.parseStackFrame_(frameString);162 expected =163 new goog.testing.stacktrace.Frame('', '', '', 'javascript:alert(0)');164 assertObjectEquals('anonymous function', expected, frame);165}166// All test strings are parsed with the conventional and long167// frame algorithms.168function testParseStackFrameInFirefoxWithQualifiedName() {169 var frameString = 'ns.method@http://some.thing/a.js:1:2';170 var frame = goog.testing.stacktrace.parseStackFrame_(frameString);171 var expected = new goog.testing.stacktrace.Frame(172 '', 'ns.method', '', 'http://some.thing/a.js:1:2');173 assertObjectEquals('anonymous function', expected, frame);174}175function testCanonicalizeFrame() {176 var frame = new goog.testing.stacktrace.Frame(177 '<window>', 'foo', 'bar', 'http://x?a=1&b=2:1');178 assertEquals(179 'canonical stack frame, everything is escaped', '<window>.foo ' +180 '[as bar] at http://x?a=1&b=2:1',181 frame.toCanonicalString());182}183function testDeobfuscateFunctionName() {184 goog.testing.stacktrace.setDeobfuscateFunctionName(function(name) {185 return name.replace(/\$/g, '.');186 });187 var frame = new goog.testing.stacktrace.Frame('', 'a$b$c', 'd$e', '');188 assertEquals(189 'deobfuscated function name', 'a.b.c [as d.e]',190 frame.toCanonicalString());191}192function testFramesToString() {193 var normalFrame = new goog.testing.stacktrace.Frame('', 'foo', '', '');194 var anonFrame = new goog.testing.stacktrace.Frame('', '', '', '');195 var frames = [normalFrame, anonFrame, null, anonFrame];196 var stack = goog.testing.stacktrace.framesToString_(frames);197 assertEquals('framesToString', '> foo\n> anonymous\n> (unknown)\n', stack);198}199function testFollowCallChain() {200 var func = function(var_args) {201 return goog.testing.stacktrace.followCallChain_();202 };203 // Created a fake type with a toString method.204 function LocalType(){};205 LocalType.prototype.toString = function() { return 'sg'; };206 // Create a mock with no expectations.207 var mock = new goog.testing.StrictMock(LocalType);208 mock.$replay();209 var frames = func(210 undefined, null, false, 0, '', {}, goog.nullFunction, mock,211 new LocalType);212 // Opera before version 10 doesn't support the caller attribute. In that213 // browser followCallChain_() returns empty stack trace.214 expectedFailures.expectFailureFor(215 goog.userAgent.OPERA && !goog.userAgent.isVersionOrHigher('10'));216 try {217 assertTrue('The stack trace consists of >=2 frames', frames.length >= 2);218 } catch (e) {219 expectedFailures.handleException(e);220 }221 if (frames.length >= 2) {222 assertEquals('innermost function is anonymous', '', frames[0].getName());223 // There are white space differences how browsers convert functions to224 // strings.225 assertEquals(226 'test function name', 'testFollowCallChain', frames[1].getName());227 }228 mock.$verify();229}230// Create a stack trace string with one modest record and one long record,231// Verify that all frames are parsed. The length of the long arg is set232// to blow Firefox 3x's stack if put through a RegExp.233function testParsingLongStackTrace() {234 var longArg =235 goog.string.buildString('(', goog.string.repeat('x', 1000000), ')');236 var stackTrace = goog.string.buildString(237 'shortFrame()@:0\n', 'longFrame', longArg,238 '@http://google.com/somescript:0\n');239 var frames = goog.testing.stacktrace.parse_(stackTrace);240 assertEquals('number of returned frames', 2, frames.length);241 var expected = new goog.testing.stacktrace.Frame('', 'shortFrame', '', '');242 assertObjectEquals('short frame', expected, frames[0]);243 assertNull('exception no frame', frames[1]);244}245function testParseStackFrameInIE10() {246 var frameString = ' at foo (http://bar:4000/bar.js:150:3)';247 var frame = goog.testing.stacktrace.parseStackFrame_(frameString);248 var expected = new goog.testing.stacktrace.Frame(249 '', 'foo', '', 'http://bar:4000/bar.js:150:3');250 assertObjectEquals('name and path', expected, frame);251 frameString = ' at Anonymous function (http://bar:4000/bar.js:150:3)';252 frame = goog.testing.stacktrace.parseStackFrame_(frameString);253 expected = new goog.testing.stacktrace.Frame(254 '', 'Anonymous function', '', 'http://bar:4000/bar.js:150:3');255 assertObjectEquals('Anonymous function', expected, frame);256 frameString = ' at Global code (http://bar:4000/bar.js:150:3)';257 frame = goog.testing.stacktrace.parseStackFrame_(frameString);258 expected = new goog.testing.stacktrace.Frame(259 '', 'Global code', '', 'http://bar:4000/bar.js:150:3');260 assertObjectEquals('Global code', expected, frame);261 frameString = ' at foo (eval code:150:3)';262 frame = goog.testing.stacktrace.parseStackFrame_(frameString);263 expected =264 new goog.testing.stacktrace.Frame('', 'foo', '', 'eval code:150:3');265 assertObjectEquals('eval code', expected, frame);266 frameString = ' at eval code (eval code:150:3)';267 frame = goog.testing.stacktrace.parseStackFrame_(frameString);268 expected =269 new goog.testing.stacktrace.Frame('', 'eval code', '', 'eval code:150:3');270 assertObjectEquals('nested eval', expected, frame);271}272function testParseStackFrameInIE11() {273 var frameString = ' at a.b.c (Unknown script code:150:3)';274 var frame = goog.testing.stacktrace.parseStackFrame_(frameString);275 var expected = new goog.testing.stacktrace.Frame(276 '', 'a.b.c', '', 'Unknown script code:150:3');277 assertObjectEquals('name and path', expected, frame);278}279function testParseStackFrameInEdge() {280 frameString = ' at a.b.c (http://host.com:80/some/file.js:101:2)';281 frame = goog.testing.stacktrace.parseStackFrame_(frameString);282 expected = new goog.testing.stacktrace.Frame(283 '', 'a.b.c', '', 'http://host.com:80/some/file.js:101:2');284 assertObjectEquals(expected, frame);285}286// Verifies that retrieving the stack trace works when the 'stack' field of an287// exception contains an array of CallSites instead of a string. This is the288// case when running in a lightweight V8 runtime (for instance, in gjstests),289// as opposed to a browser environment.290function testGetStackFrameWithV8CallSites() {291 // A function to create V8 CallSites. Note that CallSite is an extern and thus292 // cannot be mocked with closure mocks.293 function createCallSite(functionName, fileName, lineNumber, colNumber) {294 return {295 getFunctionName: goog.functions.constant(functionName),296 getFileName: goog.functions.constant(fileName),297 getLineNumber: goog.functions.constant(lineNumber),298 getColumnNumber: goog.functions.constant(colNumber)299 };300 }301 // Mock the goog.testing.stacktrace.getStack_ function, which normally302 // triggers an exception for the purpose of reading and returning its stack303 // trace. Here, pretend that V8 provided an array of CallSites instead of the304 // string that browsers provide.305 stubs.set(goog.testing.stacktrace, 'getNativeStack_', function() {306 return [307 createCallSite('fn1', 'file1', 1, 2),308 createCallSite('fn2', 'file2', 3, 4), createCallSite('fn3', 'file3', 5, 6)309 ];310 });311 // Retrieve the stacktrace. This should translate the array of CallSites into312 // a single multi-line string.313 var stackTrace = goog.testing.stacktrace.get();314 // Make sure the stack trace was translated correctly.315 var frames = stackTrace.split('\n');316 assertEquals(frames[0], '> fn1 at file1:1:2');317 assertEquals(frames[1], '> fn2 at file2:3:4');318 assertEquals(frames[2], '> fn3 at file3:5:6');...
stacktrace.js
Source:stacktrace.js
1goog.provide('goog.testing.stacktrace'); 2goog.provide('goog.testing.stacktrace.Frame'); 3goog.testing.stacktrace.Frame = function(context, name, alias, args, path) { 4 this.context_ = context; 5 this.name_ = name; 6 this.alias_ = alias; 7 this.args_ = args; 8 this.path_ = path; 9}; 10goog.testing.stacktrace.Frame.prototype.getName = function() { 11 return this.name_; 12}; 13goog.testing.stacktrace.Frame.prototype.isAnonymous = function() { 14 return ! this.name_ || this.context_ == '[object Object]'; 15}; 16goog.testing.stacktrace.Frame.prototype.toCanonicalString = function() { 17 var htmlEscape = goog.testing.stacktrace.htmlEscape_; 18 var deobfuscate = goog.testing.stacktrace.maybeDeobfuscateFunctionName_; 19 var canonical =[this.context_ ? htmlEscape(this.context_) + '.': '', this.name_ ? htmlEscape(deobfuscate(this.name_)): 'anonymous', htmlEscape(this.args_), this.alias_ ? ' [as ' + htmlEscape(deobfuscate(this.alias_)) + ']': '']; 20 if(this.path_) { 21 canonical.push(' at '); 22 if(goog.testing.stacktrace.isClosureInspectorActive_()) { 23 var lineNumber = this.path_.match(/\d+$/)[0]; 24 canonical.push('<a href="" onclick="CLOSURE_INSPECTOR___.showLine(\'', htmlEscape(this.path_), '\', \'', lineNumber, '\'); return false">', htmlEscape(this.path_), '</a>'); 25 } else { 26 canonical.push(htmlEscape(this.path_)); 27 } 28 } 29 return canonical.join(''); 30}; 31goog.testing.stacktrace.MAX_DEPTH_ = 20; 32goog.testing.stacktrace.MAX_FIREFOX_FRAMESTRING_LENGTH_ = 500000; 33goog.testing.stacktrace.IDENTIFIER_PATTERN_ = '[a-zA-Z_$][\\w$]*'; 34goog.testing.stacktrace.CHROME_ALIAS_PATTERN_ = '(?: \\[as (' + goog.testing.stacktrace.IDENTIFIER_PATTERN_ + ')\\])?'; 35goog.testing.stacktrace.CHROME_FUNCTION_NAME_PATTERN_ = '(?:new )?(?:' + goog.testing.stacktrace.IDENTIFIER_PATTERN_ + '|<anonymous>)'; 36goog.testing.stacktrace.CHROME_FUNCTION_CALL_PATTERN_ = ' (?:(.*?)\\.)?(' + goog.testing.stacktrace.CHROME_FUNCTION_NAME_PATTERN_ + ')' + goog.testing.stacktrace.CHROME_ALIAS_PATTERN_; 37goog.testing.stacktrace.URL_PATTERN_ = '((?:http|https|file)://[^\\s)]+|javascript:.*)'; 38goog.testing.stacktrace.CHROME_URL_PATTERN_ = ' (?:' + '\\(unknown source\\)' + '|' + '\\(native\\)' + '|' + '\\((?:eval at )?' + goog.testing.stacktrace.URL_PATTERN_ + '\\)' + '|' + goog.testing.stacktrace.URL_PATTERN_ + ')'; 39goog.testing.stacktrace.CHROME_STACK_FRAME_REGEXP_ = new RegExp('^ at' + '(?:' + goog.testing.stacktrace.CHROME_FUNCTION_CALL_PATTERN_ + ')?' + goog.testing.stacktrace.CHROME_URL_PATTERN_ + '$'); 40goog.testing.stacktrace.FIREFOX_FUNCTION_CALL_PATTERN_ = '(' + goog.testing.stacktrace.IDENTIFIER_PATTERN_ + ')?' + '(\\(.*\\))?@'; 41goog.testing.stacktrace.FIREFOX_STACK_FRAME_REGEXP_ = new RegExp('^' + goog.testing.stacktrace.FIREFOX_FUNCTION_CALL_PATTERN_ + '(?::0|' + goog.testing.stacktrace.URL_PATTERN_ + ')$'); 42goog.testing.stacktrace.FUNCTION_SOURCE_REGEXP_ = new RegExp('^function (' + goog.testing.stacktrace.IDENTIFIER_PATTERN_ + ')'); 43goog.testing.stacktrace.followCallChain_ = function() { 44 var frames =[]; 45 var fn = arguments.callee.caller; 46 var depth = 0; 47 while(fn && depth < goog.testing.stacktrace.MAX_DEPTH_) { 48 var fnString = Function.prototype.toString.call(fn); 49 var match = fnString.match(goog.testing.stacktrace.FUNCTION_SOURCE_REGEXP_); 50 var functionName = match ? match[1]: ''; 51 var argsBuilder =['(']; 52 if(fn.arguments) { 53 for(var i = 0; i < fn.arguments.length; i ++) { 54 var arg = fn.arguments[i]; 55 if(i > 0) { 56 argsBuilder.push(', '); 57 } 58 if(goog.isString(arg)) { 59 argsBuilder.push('"', arg, '"'); 60 } else { 61 if(arg && arg['$replay']) { 62 argsBuilder.push('goog.testing.Mock'); 63 } else { 64 argsBuilder.push(String(arg)); 65 } 66 } 67 } 68 } else { 69 argsBuilder.push('unknown'); 70 } 71 argsBuilder.push(')'); 72 var args = argsBuilder.join(''); 73 frames.push(new goog.testing.stacktrace.Frame('', functionName, '', args, '')); 74 try { 75 fn = fn.caller; 76 } catch(e) { 77 break; 78 } 79 depth ++; 80 } 81 return frames; 82}; 83goog.testing.stacktrace.parseStackFrame_ = function(frameStr) { 84 var m = frameStr.match(goog.testing.stacktrace.CHROME_STACK_FRAME_REGEXP_); 85 if(m) { 86 return new goog.testing.stacktrace.Frame(m[1]|| '', m[2]|| '', m[3]|| '', '', m[4]|| m[5]|| ''); 87 } 88 if(frameStr.length > goog.testing.stacktrace.MAX_FIREFOX_FRAMESTRING_LENGTH_) { 89 return goog.testing.stacktrace.parseLongFirefoxFrame_(frameStr); 90 } 91 m = frameStr.match(goog.testing.stacktrace.FIREFOX_STACK_FRAME_REGEXP_); 92 if(m) { 93 return new goog.testing.stacktrace.Frame('', m[1]|| '', '', m[2]|| '', m[3]|| ''); 94 } 95 return null; 96}; 97goog.testing.stacktrace.parseLongFirefoxFrame_ = function(frameStr) { 98 var firstParen = frameStr.indexOf('('); 99 var lastAmpersand = frameStr.lastIndexOf('@'); 100 var lastColon = frameStr.lastIndexOf(':'); 101 var functionName = ''; 102 if((firstParen >= 0) &&(firstParen < lastAmpersand)) { 103 functionName = frameStr.substring(0, firstParen); 104 } 105 var loc = ''; 106 if((lastAmpersand >= 0) &&(lastAmpersand + 1 < lastColon)) { 107 loc = frameStr.substring(lastAmpersand + 1); 108 } 109 var args = ''; 110 if((firstParen >= 0 && lastAmpersand > 0) &&(firstParen < lastAmpersand)) { 111 args = frameStr.substring(firstParen, lastAmpersand); 112 } 113 return new goog.testing.stacktrace.Frame('', functionName, '', args, loc); 114}; 115goog.testing.stacktrace.deobfuscateFunctionName_; 116goog.testing.stacktrace.setDeobfuscateFunctionName = function(fn) { 117 goog.testing.stacktrace.deobfuscateFunctionName_ = fn; 118}; 119goog.testing.stacktrace.maybeDeobfuscateFunctionName_ = function(name) { 120 return goog.testing.stacktrace.deobfuscateFunctionName_ ? goog.testing.stacktrace.deobfuscateFunctionName_(name): name; 121}; 122goog.testing.stacktrace.isClosureInspectorActive_ = function() { 123 return Boolean(goog.global['CLOSURE_INSPECTOR___']&& goog.global['CLOSURE_INSPECTOR___']['supportsJSUnit']); 124}; 125goog.testing.stacktrace.htmlEscape_ = function(text) { 126 return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); 127}; 128goog.testing.stacktrace.framesToString_ = function(frames) { 129 var lastIndex = frames.length - 1; 130 while(frames[lastIndex]&& frames[lastIndex].isAnonymous()) { 131 lastIndex --; 132 } 133 var privateAssertIndex = - 1; 134 for(var i = 0; i < frames.length; i ++) { 135 if(frames[i]&& frames[i].getName() == '_assert') { 136 privateAssertIndex = i; 137 break; 138 } 139 } 140 var canonical =[]; 141 for(var i = privateAssertIndex + 1; i <= lastIndex; i ++) { 142 canonical.push('> '); 143 if(frames[i]) { 144 canonical.push(frames[i].toCanonicalString()); 145 } else { 146 canonical.push('(unknown)'); 147 } 148 canonical.push('\n'); 149 } 150 return canonical.join(''); 151}; 152goog.testing.stacktrace.parse_ = function(stack) { 153 var lines = stack.replace(/\s*$/, '').split('\n'); 154 var frames =[]; 155 for(var i = 0; i < lines.length; i ++) { 156 frames.push(goog.testing.stacktrace.parseStackFrame_(lines[i])); 157 } 158 return frames; 159}; 160goog.testing.stacktrace.canonicalize = function(stack) { 161 var frames = goog.testing.stacktrace.parse_(stack); 162 return goog.testing.stacktrace.framesToString_(frames); 163}; 164goog.testing.stacktrace.get = function() { 165 var stack = new Error().stack; 166 var frames = stack ? goog.testing.stacktrace.parse_(stack): goog.testing.stacktrace.followCallChain_(); 167 return goog.testing.stacktrace.framesToString_(frames); 168}; ...
DebuggerPresentationUtils.js
Source:DebuggerPresentationUtils.js
1// Copyright 2015 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4WebInspector.DebuggerPresentationUtils = {}5/**6 * @param {?WebInspector.DebuggerModel} debuggerModel7 * @param {!Array.<!ConsoleAgent.CallFrame>=} stackTrace8 * @param {!ConsoleAgent.AsyncStackTrace=} asyncStackTrace9 * @param {boolean=} showBlackboxed10 * @return {?ConsoleAgent.CallFrame}11 */12WebInspector.DebuggerPresentationUtils.callFrameAnchorFromStackTrace = function(debuggerModel, stackTrace, asyncStackTrace, showBlackboxed)13{14 /**15 * @param {?Array.<!ConsoleAgent.CallFrame>=} stackTrace16 * @return {?ConsoleAgent.CallFrame}17 */18 function innerCallFrameAnchorFromStackTrace(stackTrace)19 {20 if (!stackTrace || !stackTrace.length)21 return null;22 if (showBlackboxed)23 return stackTrace[0];24 for (var i = 0; i < stackTrace.length; ++i) {25 var script = debuggerModel && debuggerModel.scriptForId(stackTrace[i].scriptId);26 var blackboxed = script ?27 WebInspector.BlackboxSupport.isBlackboxed(script.sourceURL, script.isContentScript()) :28 WebInspector.BlackboxSupport.isBlackboxedURL(stackTrace[i].url);29 if (!blackboxed)30 return stackTrace[i];31 }32 return null;33 }34 var callFrame = innerCallFrameAnchorFromStackTrace(stackTrace);35 if (callFrame)36 return callFrame;37 while (asyncStackTrace) {38 callFrame = innerCallFrameAnchorFromStackTrace(asyncStackTrace.callFrames);39 if (callFrame)40 return callFrame;41 asyncStackTrace = asyncStackTrace.asyncStackTrace;42 }43 return stackTrace ? stackTrace[0] : null;...
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.evaluate(() => {6 console.log('Hello from the browser');7 console.error('Hello from the browser');8 });9 await browser.close();10})();11const puppeteer = require('puppeteer');12(async () => {13 const browser = await puppeteer.launch();14})();15const puppeteer = require('puppeteer');16(async () => {17 const browser = await puppeteer.launch();18 await browser.close();19})();20const puppeteer = require('puppeteer');21(async () => {22 const browser = await puppeteer.launch();23 const page = await browser.newPage();24 await browser.close();25})();26const puppeteer = require('puppeteer');27(async () => {28 const browser = await puppeteer.launch();29 const pages = await browser.pages();30 await browser.close();31})();32const puppeteer = require('puppeteer');33(async () => {34 const browser = await puppeteer.launch();35 const target = await browser.target();36 await browser.close();37})();38const puppeteer = require('puppeteer');39(async () => {40 const browser = await puppeteer.launch();41 const targets = await browser.targets();42 await browser.close();43})();44const puppeteer = require('puppeteer');45(async () => {46 const browser = await puppeteer.launch();
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.evaluate(() => { throw new Error('This is an error!'); });6 const stackTrace = await page.evaluate(() => { return new Error().stack; });7 console.log(stackTrace);8 await browser.close();9})();10const puppeteer = require('puppeteer');11(async () => {12 const browser = await puppeteer.launch();13 const page = await browser.newPage();14 await page.evaluate(() => { throw new Error('This is an error!'); });15 const stackTrace = await page.evaluate(() => { return new Error().stack; });16 console.log(stackTrace);17 await browser.close();18})();19const puppeteer = require('puppeteer');20(async () => {21 const browser = await puppeteer.launch();22 const page = await browser.newPage();
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 const stackTrace = await page.evaluate(() => {6 return new Error('this is an error').stack;7 });8 console.log(stackTrace);9 await browser.close();10})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3(async () => {4 const browser = await puppeteer.launch();5 const page = await browser.newPage();6 const stackTrace = await page.evaluate(() => {7 return new Error().stack;8 });9 fs.writeFile('stackTrace.txt', stackTrace, (err) => {10 if (err) throw err;11 console.log('The file has been saved!');12 });13 await browser.close();14})();15 at ExecutionContext._evaluateInternal (/Users/username/stackTrace/node_modules/puppeteer/lib/ExecutionContext.js:122:19)16 at process._tickCallback (internal/process/next_tick.js:68:7)17const stackTrace = await page.evaluate(() => {18 return new Error().stack;19});20const stackTrace = await page.evaluate(() => {21 return new Error().stack;22});23- [Puppeteer GitHub Repository](
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3const path = require('path');4(async () => {5 const browser = await puppeteer.launch();6 const page = await browser.newPage();7 await page.screenshot({path: 'google.png'});8 await page.evaluate(() => {9 throw new Error('This is an error');10 });11 const stackTrace = await page.evaluate(() => {12 const stack = new Error().stack;13 return stack;14 });15 fs.writeFileSync(path.join(__dirname, 'stackTrace.txt'), stackTrace);16 await browser.close();17})();18const puppeteer = require('puppeteer');19const fs = require('fs');20const path = require('path');21(async () => {22 const browser = await puppeteer.launch();23 const page = await browser.newPage();24 await page.screenshot({path: 'google.png'});25 await page.evaluate(() => {26 throw new Error('This is an error');27 });28 const stackTrace = await page.evaluate(() => {29 const stack = new Error().stack;30 return stack;31 });32 fs.writeFileSync(path.join(__dirname, 'stackTrace.txt'), stackTrace);33 await browser.close();34})();35const puppeteer = require('puppeteer');36const fs = require('fs');37const path = require('path');38(async () => {39 const browser = await puppeteer.launch();40 const page = await browser.newPage();41 await page.screenshot({path: 'google.png'});42 await page.evaluate(() => {43 throw new Error('This is an error');44 });45 const stackTrace = await page.evaluate(() => {46 const stack = new Error().stack;47 return stack;48 });49 fs.writeFileSync(path.join(__dirname, 'stackTrace.txt'), stackTrace);50 await browser.close();51})();52const puppeteer = require('puppeteer');53const fs = require('fs');54const path = require('path');55(async () => {56 const browser = await puppeteer.launch();
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3(async () => {4const browser = await puppeteer.launch({headless: false, slowMo: 100});5const page = await browser.newPage();6await page.screenshot({path: 'example.png'});7await page.evaluate(() => {8 function foo() {9 bar();10 }11 function bar() {12 baz();13 }14 function baz() {15 console.log('hello from baz');16 throw new Error('oops');17 }18 foo();19});20await page.close();21await browser.close();22})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3(async () => {4 const browser = await puppeteer.launch();5 const page = await browser.newPage();6 const stackTrace = await page.evaluate(() => {7 throw new Error('Error in page.evaluate');8 }).catch(e => e.stack);9 console.log(stackTrace);10 await browser.close();11})();12**puppeteer-extra-plugin-stealth** is a plugin for **puppeteer-extra** that is designed to help prevent detection by headless chrome. It is a fork of [puppeteer-extra-plugin-anonymize-ua](
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!