Skip to content

Commit

Permalink
core(target-manager): ignore target if type is unknown (#16221)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine authored Nov 5, 2024
1 parent 7e4e8c0 commit 3adb84f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/gather/driver/target-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ class TargetManager extends ProtocolEventEmitter {
// Sometimes targets can be closed before we even have a chance to listen to their network activity.
if (/Target closed/.test(err.message)) return;

// `Target.getTargetInfo` is not implemented for certain target types.
// Lighthouse isn't interested in these targets anyway so we can just ignore them.
if (/'Target.getTargetInfo' wasn't found/.test(err)) return;

// Worker targets can be a bit fickle and we only enable them for diagnostic purposes.
// We shouldn't throw a fatal error if there were issues attaching to them.
if (targetType === 'worker') {
Expand Down
15 changes: 15 additions & 0 deletions core/test/gather/driver/target-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,21 @@ describe('TargetManager', () => {
expect(sendMock.findAllInvocations('Runtime.runIfWaitingForDebugger')).toHaveLength(1);
});

it('should ignore errors if Target.getTargetInfo is undefined', async () => {
targetInfo.type = 'worker';
sendMock
.mockResponse('Target.getTargetInfo', () => {
throw new Error(`'Target.getTargetInfo' wasn't found`);
});
await targetManager.enable();

const invocations = sendMock.findAllInvocations('Target.setAutoAttach');
expect(invocations).toHaveLength(0);

// Should still be resumed.
expect(sendMock.findAllInvocations('Runtime.runIfWaitingForDebugger')).toHaveLength(1);
});

it('should ignore targets that are not frames or web workers', async () => {
targetInfo.type = 'service_worker';
sendMock
Expand Down

0 comments on commit 3adb84f

Please sign in to comment.