Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove browsertime extension #2124

Merged
merged 3 commits into from
May 16, 2024
Merged
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
2 changes: 1 addition & 1 deletion jsdoc/tutorials/05-Interact-Browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default async function (context, commands) {


## Cache
You can clear the browser cache from your script. The command works in Chrome, Edge and Firefox. Use it when you want to clear the browser cache between different URLs.
You can clear the browser cache from your script. The command works in Chrome and Edge. Use it when you want to clear the browser cache between different URLs.

### Clear cache and cookies

Expand Down
24 changes: 3 additions & 21 deletions lib/core/engine/command/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const log = intel.getLogger('browsertime.command.cache');
* @hideconstructor
*/
export class Cache {
constructor(browser, browserName, extensionServer, cdp) {
constructor(browser, browserName, cdp) {
/**
* @private
*/
Expand All @@ -17,10 +17,6 @@ export class Cache {
* @private
*/
this.browserName = browserName;
/**
* @private
*/
this.extensionServer = extensionServer;
/**
* @private
*/
Expand All @@ -30,7 +26,6 @@ export class Cache {
/**
* Clears the browser cache. This includes both cache and cookies.
*
* For Firefox, it uses the extensionServer setup with specific options.
* For Chrome and Edge, it uses the Chrome DevTools Protocol (CDP) commands.
* If the browser is not supported, logs an error message.
*
Expand All @@ -40,13 +35,7 @@ export class Cache {
* @returns {Promise<void>} A promise that resolves when the cache and cookies are cleared.
*/
async clear() {
if (this.browserName === 'firefox') {
const options = {
cacheClearRaw: true,
browser: 'firefox'
};
return this.extensionServer.setup(undefined, this.browser, options);
} else if (this.browserName === 'chrome' || this.browserName === 'edge') {
if (this.browserName === 'chrome' || this.browserName === 'edge') {
await this.cdp.send('Network.enable');
await this.cdp.send('Network.clearBrowserCache');
return this.cdp.send('Network.clearBrowserCookies');
Expand All @@ -58,7 +47,6 @@ export class Cache {
/**
* Clears the browser cache while keeping the cookies.
*
* For Firefox, it uses the extensionServer setup with specific options.
* For Chrome and Edge, it uses the Chrome DevTools Protocol (CDP) command to clear the cache.
* If the browser is not supported, logs an error message.
*
Expand All @@ -68,13 +56,7 @@ export class Cache {
* @returns {Promise<void>} A promise that resolves when the cache is cleared but cookies are kept.
*/
async clearKeepCookies() {
if (this.browserName === 'firefox') {
const options = {
clearCacheKeepCookies: true,
browser: 'firefox'
};
return this.extensionServer.setup(undefined, this.browser, options);
} else if (this.browserName === 'chrome' || this.browserName === 'edge') {
if (this.browserName === 'chrome' || this.browserName === 'edge') {
await this.cdp.send('Network.enable');
return this.cdp.send('Network.clearBrowserCache');
} else {
Expand Down
26 changes: 6 additions & 20 deletions lib/core/engine/command/measure.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class Measure {
pageCompleteCheck,
result,
engineDelegate,
extensionServer,
storageManager,
videos,
scriptsByCategory,
Expand Down Expand Up @@ -87,10 +86,6 @@ export class Measure {
* @private
*/
this.recordVideo = options.visualMetrics || options.video;
/**
* @private
*/
this.extensionServer = extensionServer;
/**
* @private
*/
Expand Down Expand Up @@ -244,17 +239,13 @@ export class Measure {
*/
async _navigate(url) {
log.info('Navigating to url %s iteration %s', url, this.index);
if (this.numberOfVisitedPages === 0) {
await this.extensionServer.setup(url, this.browser, this.options);

// There's a bug that we introduced when moving cookie handling to CDP
if (
this.numberOfVisitedPages === 0 && // There's a bug that we introduced when moving cookie handling to CDP
// and this is the hack to fix that.
if (
(this.options.cookie && this.options.browser === 'chrome') ||
this.options.browser === 'edge'
) {
await this.engineDelegate.setCookies(url, this.options.cookie);
}
((this.options.cookie && this.options.browser === 'chrome') ||
this.options.browser === 'edge')
) {
await this.engineDelegate.setCookies(url, this.options.cookie);
}
if (this.numberOfVisitedPages === 0) {
await this.engineDelegate.beforeStartIteration(this.browser, this.index);
Expand Down Expand Up @@ -302,11 +293,6 @@ export class Measure {
log.info('Start to measure');
}

// On the first page of an iteration, do what you need to do!
if (this.numberOfVisitedPages === 0 && url) {
// We can only setup the extension if we have a URL at the moment
await this.extensionServer.setup(url, this.browser, this.options);
}
if (this.numberOfVisitedPages === 0) {
await this.engineDelegate.beforeStartIteration(this.browser, this.index);
}
Expand Down
4 changes: 1 addition & 3 deletions lib/core/engine/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export class Commands {
result,
storageManager,
pageCompleteCheck,
extensionServer,
context,
videos,
screenshotManager,
Expand All @@ -55,7 +54,6 @@ export class Commands {
pageCompleteCheck,
result,
engineDelegate,
extensionServer,
storageManager,
videos,
scriptsByCategory,
Expand Down Expand Up @@ -181,7 +179,7 @@ export class Commands {
* Manages the browser's cache.
* @type {Cache}
*/
this.cache = new Cache(browser, options.browser, extensionServer, cdp);
this.cache = new Cache(browser, options.browser, cdp);

/**
* Adds metadata to the user journey.
Expand Down
3 changes: 0 additions & 3 deletions lib/core/engine/iteration.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { SeleniumRunner } from '../seleniumRunner.js';
import { preURL } from '../../support/preURL.js';
import { setResourceTimingBufferSize } from '../../support/setResourceTimingBufferSize.js';
import { ScreenshotManager } from '../../screenshot/index.js';
import { ExtensionServer } from '../../extensionserver/index.js';
import { Video } from '../../video/video.js';
import { stop } from '../../support/stop.js';

Expand Down Expand Up @@ -79,7 +78,6 @@ export class Iteration {
const result = [];
const batteryTemperature = {};

const extensionServer = new ExtensionServer(options);
const engineDelegate = this.engineDelegate;

try {
Expand Down Expand Up @@ -112,7 +110,6 @@ export class Iteration {
result,
this.storageManager,
this.pageCompleteCheck,
extensionServer,
context,
videos,
screenshotManager,
Expand Down
20 changes: 0 additions & 20 deletions lib/extensionserver/httpServer.js

This file was deleted.

46 changes: 0 additions & 46 deletions lib/extensionserver/index.js

This file was deleted.

39 changes: 0 additions & 39 deletions lib/extensionserver/setup.js

This file was deleted.

14 changes: 0 additions & 14 deletions lib/firefox/webdriver/builder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import { platform } from 'node:os';
import {
ServiceBuilder,
Expand All @@ -18,12 +15,10 @@ import { disableTrackingProtectionPreferences } from '../settings/disableTrackin
import { toArray } from '../../support/util.js';
import { Android, isAndroidConfigured } from '../../android/index.js';
const log = intel.getLogger('browsertime.firefox');
const __dirname = path.dirname(fileURLToPath(import.meta.url));

export async function configureBuilder(builder, baseDir, options) {
// Here we configure everything that we need to start Firefox
const firefoxConfig = options.firefox || {};
const moduleRootPath = resolve(__dirname, '..', '..', '..');

let geckodriverPath = get(firefoxConfig, 'geckodriverPath');
if (!geckodriverPath) {
Expand Down Expand Up @@ -112,15 +107,6 @@ export async function configureBuilder(builder, baseDir, options) {
ffOptions.setPreference('detach', true);
}

// Browsertime own extension, only load it when we need it
// We should be able to only install it only when needed, but that could break scripting

if (!firefoxConfig.disableBrowsertimeExtension) {
ffOptions.addExtensions(
resolve(moduleRootPath, 'vendor', 'browsertime-0.18.0-an+fx.xpi')
);
}

if (options.extension) {
const extensions = Array.isArray(options.extension)
? options.extension
Expand Down
9 changes: 2 additions & 7 deletions lib/support/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,6 @@ export function parseCommandLine() {
'timestamp,nsHttp:5,cache2:5,nsSocketTransport:5,nsHostResolver:5',
group: 'firefox'
})
.option('firefox.disableBrowsertimeExtension', {
describe: 'Disable installing the browsertime extension.',
type: 'boolean',
group: 'firefox'
})
.option('firefox.noDefaultPrefs', {
describe: 'Prevents browsertime from setting its default preferences.',
default: false,
Expand Down Expand Up @@ -1081,11 +1076,11 @@ export function parseCommandLine() {
.option('requestheader', {
alias: 'r',
describe:
'Request header that will be added to the request. Add multiple instances to add multiple request headers. Works for Firefox and Chrome. Use the following format key:value'
'Request header that will be added to the request. Add multiple instances to add multiple request headers. Works for Edge and Chrome. Use the following format key:value'
})
.option('cookie', {
describe:
'Cookie that will be added to the request. Add multiple instances to add multiple request cookies. Works for Firefox and Chrome. Use the following format cookieName=cookieValue'
'Cookie that will be added to the request. Add multiple instances to add multiple request cookies. Works for Firefox, Chrome and Edge. Use the following format cookieName=cookieValue'
})
.option('injectJs', {
describe:
Expand Down
Binary file removed vendor/browsertime-0.18.0-an+fx.xpi
Binary file not shown.
Binary file removed vendor/browsertime-extension.crx
Binary file not shown.
Loading