chore: remove installAsyncStackHooks
helper (#6186)
* chore: remove `installAsyncStackHooks` helper This code was written when browsers/Node didn't support errors in async functions very well. They now do a much better job of this, so we can lose the additonal complexity from our codebase and leave it to the host environment :) * lazy launcher is private * remove async stack test
This commit is contained in:
parent
19f188a852
commit
12434663e2
@ -1,11 +0,0 @@
|
|||||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
||||||
|
|
||||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [Puppeteer](./puppeteer.puppeteer.md) > [\_lazyLauncher](./puppeteer.puppeteer._lazylauncher.md)
|
|
||||||
|
|
||||||
## Puppeteer.\_lazyLauncher property
|
|
||||||
|
|
||||||
<b>Signature:</b>
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
_lazyLauncher: ProductLauncher;
|
|
||||||
```
|
|
@ -40,7 +40,6 @@ const puppeteer = require('puppeteer');
|
|||||||
| [\_\_productName](./puppeteer.puppeteer.__productname.md) | | string | |
|
| [\_\_productName](./puppeteer.puppeteer.__productname.md) | | string | |
|
||||||
| [\_changedProduct](./puppeteer.puppeteer._changedproduct.md) | | boolean | |
|
| [\_changedProduct](./puppeteer.puppeteer._changedproduct.md) | | boolean | |
|
||||||
| [\_isPuppeteerCore](./puppeteer.puppeteer._ispuppeteercore.md) | | boolean | |
|
| [\_isPuppeteerCore](./puppeteer.puppeteer._ispuppeteercore.md) | | boolean | |
|
||||||
| [\_lazyLauncher](./puppeteer.puppeteer._lazylauncher.md) | | [ProductLauncher](./puppeteer.productlauncher.md) | |
|
|
||||||
| [\_preferredRevision](./puppeteer.puppeteer._preferredrevision.md) | | string | |
|
| [\_preferredRevision](./puppeteer.puppeteer._preferredrevision.md) | | string | |
|
||||||
| [devices](./puppeteer.puppeteer.devices.md) | | [DevicesMap](./puppeteer.devicesmap.md) | |
|
| [devices](./puppeteer.puppeteer.devices.md) | | [DevicesMap](./puppeteer.devicesmap.md) | |
|
||||||
| [errors](./puppeteer.puppeteer.errors.md) | | [PuppeteerErrors](./puppeteer.puppeteererrors.md) | |
|
| [errors](./puppeteer.puppeteer.errors.md) | | [PuppeteerErrors](./puppeteer.puppeteererrors.md) | |
|
||||||
|
@ -13,13 +13,10 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
// @ts-nocheck
|
|
||||||
|
|
||||||
/* This file is used in two places:
|
/* This file is used in one place:
|
||||||
* 1) the coverage-utils use it to gain a list of all methods we check for test
|
* 1) the coverage-utils use it to gain a list of all methods we check for test
|
||||||
* coverage on
|
* coverage on
|
||||||
* 2) index.js uses it to iterate through all methods and call
|
|
||||||
* helper.installAsyncStackHooks on
|
|
||||||
*/
|
*/
|
||||||
module.exports = {
|
module.exports = {
|
||||||
Accessibility: require('./common/Accessibility').Accessibility,
|
Accessibility: require('./common/Accessibility').Accessibility,
|
||||||
|
@ -61,7 +61,7 @@ export class Puppeteer {
|
|||||||
_isPuppeteerCore: boolean;
|
_isPuppeteerCore: boolean;
|
||||||
_changedProduct = false;
|
_changedProduct = false;
|
||||||
__productName: string;
|
__productName: string;
|
||||||
_lazyLauncher: ProductLauncher;
|
private _lazyLauncher: ProductLauncher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
|
@ -28,10 +28,6 @@ const closeAsync = promisify(fs.close);
|
|||||||
|
|
||||||
export const debugError = debug('puppeteer:error');
|
export const debugError = debug('puppeteer:error');
|
||||||
|
|
||||||
interface AnyClass {
|
|
||||||
prototype: object;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getExceptionMessage(
|
function getExceptionMessage(
|
||||||
exceptionDetails: Protocol.Runtime.ExceptionDetails
|
exceptionDetails: Protocol.Runtime.ExceptionDetails
|
||||||
): string {
|
): string {
|
||||||
@ -95,39 +91,6 @@ async function releaseObject(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function installAsyncStackHooks(classType: AnyClass): void {
|
|
||||||
for (const methodName of Reflect.ownKeys(classType.prototype)) {
|
|
||||||
const method = Reflect.get(classType.prototype, methodName);
|
|
||||||
if (
|
|
||||||
methodName === 'constructor' ||
|
|
||||||
typeof methodName !== 'string' ||
|
|
||||||
methodName.startsWith('_') ||
|
|
||||||
typeof method !== 'function' ||
|
|
||||||
method.constructor.name !== 'AsyncFunction'
|
|
||||||
)
|
|
||||||
continue;
|
|
||||||
Reflect.set(classType.prototype, methodName, function (...args) {
|
|
||||||
const syncStack = {
|
|
||||||
stack: '',
|
|
||||||
};
|
|
||||||
Error.captureStackTrace(syncStack);
|
|
||||||
return method.call(this, ...args).catch((error) => {
|
|
||||||
const stack = syncStack.stack.substring(
|
|
||||||
syncStack.stack.indexOf('\n') + 1
|
|
||||||
);
|
|
||||||
const clientStack = stack.substring(stack.indexOf('\n'));
|
|
||||||
if (
|
|
||||||
error instanceof Error &&
|
|
||||||
error.stack &&
|
|
||||||
!error.stack.includes(clientStack)
|
|
||||||
)
|
|
||||||
error.stack += '\n -- ASYNC --\n' + stack;
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PuppeteerEventListener {
|
export interface PuppeteerEventListener {
|
||||||
emitter: CommonEventEmitter;
|
emitter: CommonEventEmitter;
|
||||||
eventName: string | symbol;
|
eventName: string | symbol;
|
||||||
@ -277,7 +240,6 @@ export const helper = {
|
|||||||
addEventListener,
|
addEventListener,
|
||||||
removeEventListeners,
|
removeEventListeners,
|
||||||
valueFromRemoteObject,
|
valueFromRemoteObject,
|
||||||
installAsyncStackHooks,
|
|
||||||
getExceptionMessage,
|
getExceptionMessage,
|
||||||
releaseObject,
|
releaseObject,
|
||||||
};
|
};
|
||||||
|
@ -14,12 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// api.ts has to use module.exports as it's also consumed by DocLint which runs
|
|
||||||
// on Node.
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
||||||
const api = require('./api');
|
|
||||||
|
|
||||||
import { helper } from './common/helper';
|
|
||||||
import { Puppeteer } from './common/Puppeteer';
|
import { Puppeteer } from './common/Puppeteer';
|
||||||
import { PUPPETEER_REVISIONS } from './revisions';
|
import { PUPPETEER_REVISIONS } from './revisions';
|
||||||
import pkgDir from 'pkg-dir';
|
import pkgDir from 'pkg-dir';
|
||||||
@ -27,11 +21,6 @@ import pkgDir from 'pkg-dir';
|
|||||||
export const initializePuppeteer = (packageName: string): Puppeteer => {
|
export const initializePuppeteer = (packageName: string): Puppeteer => {
|
||||||
const puppeteerRootDirectory = pkgDir.sync(__dirname);
|
const puppeteerRootDirectory = pkgDir.sync(__dirname);
|
||||||
|
|
||||||
for (const className in api) {
|
|
||||||
if (typeof api[className] === 'function')
|
|
||||||
helper.installAsyncStackHooks(api[className]);
|
|
||||||
}
|
|
||||||
|
|
||||||
let preferredRevision = PUPPETEER_REVISIONS.chromium;
|
let preferredRevision = PUPPETEER_REVISIONS.chromium;
|
||||||
const isPuppeteerCore = packageName === 'puppeteer-core';
|
const isPuppeteerCore = packageName === 'puppeteer-core';
|
||||||
// puppeteer-core ignores environment variables
|
// puppeteer-core ignores environment variables
|
||||||
@ -43,16 +32,10 @@ export const initializePuppeteer = (packageName: string): Puppeteer => {
|
|||||||
if (!isPuppeteerCore && product === 'firefox')
|
if (!isPuppeteerCore && product === 'firefox')
|
||||||
preferredRevision = PUPPETEER_REVISIONS.firefox;
|
preferredRevision = PUPPETEER_REVISIONS.firefox;
|
||||||
|
|
||||||
const puppeteer = new Puppeteer(
|
return new Puppeteer(
|
||||||
puppeteerRootDirectory,
|
puppeteerRootDirectory,
|
||||||
preferredRevision,
|
preferredRevision,
|
||||||
isPuppeteerCore,
|
isPuppeteerCore,
|
||||||
product
|
product
|
||||||
);
|
);
|
||||||
|
|
||||||
// The introspection in `Helper.installAsyncStackHooks` references
|
|
||||||
// `Puppeteer._launcher` before the Puppeteer ctor is called, such that an
|
|
||||||
// invalid Launcher is selected at import, so we reset it.
|
|
||||||
puppeteer._lazyLauncher = undefined;
|
|
||||||
return puppeteer;
|
|
||||||
};
|
};
|
||||||
|
@ -441,6 +441,11 @@ describe('Launcher specs', function () {
|
|||||||
|
|
||||||
after(async () => {
|
after(async () => {
|
||||||
const { puppeteer } = getTestState();
|
const { puppeteer } = getTestState();
|
||||||
|
/* launcher is a private property so we don't want our users doing this
|
||||||
|
* but we need to reset the state fully here for testing different
|
||||||
|
* browser launchers
|
||||||
|
*/
|
||||||
|
// @ts-expect-error
|
||||||
puppeteer._lazyLauncher = undefined;
|
puppeteer._lazyLauncher = undefined;
|
||||||
puppeteer._productName = productName;
|
puppeteer._productName = productName;
|
||||||
});
|
});
|
||||||
|
@ -119,21 +119,6 @@ describe('Page', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describeFailsFirefox('Async stacks', () => {
|
|
||||||
it('should work', async () => {
|
|
||||||
const { page, server } = getTestState();
|
|
||||||
|
|
||||||
server.setRoute('/empty.html', (req, res) => {
|
|
||||||
res.statusCode = 204;
|
|
||||||
res.end();
|
|
||||||
});
|
|
||||||
let error = null;
|
|
||||||
await page.goto(server.EMPTY_PAGE).catch((error_) => (error = error_));
|
|
||||||
expect(error).not.toBe(null);
|
|
||||||
expect(error.stack).toContain(__filename);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// This test fails on Firefox on CI consistently but cannot be replicated
|
// This test fails on Firefox on CI consistently but cannot be replicated
|
||||||
// locally. Skipping for now to unblock the Mitt release and given FF support
|
// locally. Skipping for now to unblock the Mitt release and given FF support
|
||||||
// isn't fully done yet but raising an issue to ask the FF folks to have a
|
// isn't fully done yet but raising an issue to ask the FF folks to have a
|
||||||
|
Loading…
Reference in New Issue
Block a user