Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/DevtoolsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {PuppeteerDevToolsConnection} from './DevToolsConnectionAdapter.js';

Check failure on line 7 in src/DevtoolsUtils.ts

View workflow job for this annotation

GitHub Actions / [Required] Check docs updated

'../node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkManager.js' import is restricted from being used by a pattern. Import only the devtools-frontend code exported via node_modules/chrome-devtools-frontend/mcp/mcp.js
import {Mutex} from './Mutex.js';
import {DevTools} from './third_party/index.js';

Check failure on line 9 in src/DevtoolsUtils.ts

View workflow job for this annotation

GitHub Actions / [Required] Check correct format

There should be at least one empty line between import groups
import {NetworkManager} from '../node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkManager.js';

Check failure on line 10 in src/DevtoolsUtils.ts

View workflow job for this annotation

GitHub Actions / [Required] Check correct format

`../node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkManager.js` import should occur before import of `./DevToolsConnectionAdapter.js`

Check failure on line 10 in src/DevtoolsUtils.ts

View workflow job for this annotation

GitHub Actions / [Required] Check correct format

There should be at least one empty line between import groups

Check failure on line 10 in src/DevtoolsUtils.ts

View workflow job for this annotation

GitHub Actions / [Required] Check correct format

'../node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkManager.js' import is restricted from being used by a pattern. Import only the devtools-frontend code exported via node_modules/chrome-devtools-frontend/mcp/mcp.js
import type {
Browser,
ConsoleMessage,
Expand Down Expand Up @@ -144,6 +145,7 @@

const targetManager = universe.context.get(DevTools.TargetManager);
targetManager.observeModels(DevTools.DebuggerModel, SKIP_ALL_PAUSES);
targetManager.observeModels(NetworkManager, DISABLE_NETWORK);

const target = targetManager.createTarget(
'main',
Expand Down Expand Up @@ -172,6 +174,23 @@
},
};

// Not recording network requests in the DevTools universe.
//
// The network requests are collected through pptr and there isn't a use case for
// enabling devtools SDK's network domain.
//
// If enabled, the NetworkManager collects NetworkRequests that are not properly
// deleted when the page navigates away. See http://b/493046293 for context (internal).
const DISABLE_NETWORK = {
modelAdded(model: NetworkManager): void {
void model.target().networkAgent().invoke_disable();
},

modelRemoved(): void {
// Do nothing.
},
};

/**
* Constructed from Runtime.ExceptionDetails of an uncaught error.
*
Expand Down
26 changes: 26 additions & 0 deletions tests/DevtoolsUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@

import sinon from 'sinon';

import {UniverseManager} from '../src/DevtoolsUtils.js';

Check failure on line 12 in tests/DevtoolsUtils.test.ts

View workflow job for this annotation

GitHub Actions / [Required] Check docs updated

'../node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkManager.js' import is restricted from being used by a pattern. Import only the devtools-frontend code exported via node_modules/chrome-devtools-frontend/mcp/mcp.js
import {DevTools} from '../src/third_party/index.js';
import type {Browser, Target} from '../src/third_party/index.js';
import {Events as NetworkManagerEvents, NetworkManager} from '../node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkManager.js';

Check failure on line 15 in tests/DevtoolsUtils.test.ts

View workflow job for this annotation

GitHub Actions / [Required] Check correct format

`../node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkManager.js` import should occur before import of `../src/DevtoolsUtils.js`

Check failure on line 15 in tests/DevtoolsUtils.test.ts

View workflow job for this annotation

GitHub Actions / [Required] Check correct format

'../node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkManager.js' import is restricted from being used by a pattern. Import only the devtools-frontend code exported via node_modules/chrome-devtools-frontend/mcp/mcp.js

import {serverHooks} from './server.js';
import {
getMockBrowser,
getMockPage,
html,
mockListener,
withBrowser,
} from './utils.js';

describe('UniverseManager', () => {
const server = serverHooks();

afterEach(() => {
sinon.restore();
});
Expand Down Expand Up @@ -86,4 +91,25 @@
sinon.assert.notCalled(pausedSpy);
});
});

it('disables network domain', async () => {
server.addHtmlRoute('/test', html`<div>Test</div>`);

await withBrowser(async (browser, page) => {
const manager = new UniverseManager(browser);
await manager.init([page]);
const targetUniverse = manager.get(page);
assert.ok(targetUniverse);

const networkManager = targetUniverse.target.model(NetworkManager);
assert.ok(networkManager);

const requestStartedSpy = sinon.stub();
networkManager.addEventListener(NetworkManagerEvents.RequestStarted as any, requestStartedSpy);

Check failure on line 108 in tests/DevtoolsUtils.test.ts

View workflow job for this annotation

GitHub Actions / [Required] Check docs updated

Unexpected any. Specify a different type

Check failure on line 108 in tests/DevtoolsUtils.test.ts

View workflow job for this annotation

GitHub Actions / [Required] Check correct format

Unexpected any. Specify a different type

await page.goto(server.getRoute('/test'));

sinon.assert.notCalled(requestStartedSpy);
});
});
});
Loading