cypress-har-generator icon indicating copy to clipboard operation
cypress-har-generator copied to clipboard

Adapt the plugin for Firefox

Open derevnjuk opened this issue 4 years ago • 5 comments

Cypress doesn't support Firefox yet

https://github.com/cypress-io/cypress/issues/1096 https://bugzilla.mozilla.org/show_bug.cgi?id=1605512

derevnjuk avatar Dec 03 '19 09:12 derevnjuk

Blocked by #6

derevnjuk avatar Dec 03 '19 13:12 derevnjuk

So the priority for use in Firefox is low? As in, not a high priority? Just wanting some clarification on this topic as I have no intention to be forced to use Chrome for any project or tool.

weo3dev avatar Dec 18 '19 21:12 weo3dev

@weo3dev As noted by @ArtemDerevnjuk above comment this is currently blocked by Firefox capabilities, as you can read in https://github.com/NeuraLegion/cypress-har-generator/issues/6#issuecomment-566682943 we are indeed working with their team on this.

The "low" priority is that this task cannot progress until fixed somewhere else. As a user of Firefox and a lover of opensource I promise you we will do our best to allow Firefox support when it's technically possible.

We will keep this issue updated with our progress, be sure to subscribe to it if you want to get notification when this happens.

bararchy avatar Dec 18 '19 21:12 bararchy

Thank you so very much for the quickest response ever! I was reading #6 and I guess I was confused in my brain so now it makes sense the order in which development has to proceed.

Definitely subscribed to a PR tracker and an issue tracker so I can stay up to date.

Thank you again, keep up the good work!!

weo3dev avatar Dec 18 '19 21:12 weo3dev

@derevnjuk What are your thoughts on making the plugin no-op in the Firefox browser (and any other unsupported browsers) instead of throwing an error: https://github.com/NeuraLegion/cypress-har-generator/blob/41a41f33b77cb634bafa9776efde2595e1ab1ae7/src/Plugin.ts#L60-L64

For example, could we instead do something like this:

diff --git a/src/Plugin.ts b/src/Plugin.ts
index 4a4a4e7..5947a6e 100644
--- a/src/Plugin.ts
+++ b/src/Plugin.ts
@@ -44,6 +44,7 @@ export class Plugin {
   private networkObservable?: Observer<NetworkRequest>;
   private addr?: Addr;
   private _connection?: Connection;
+  private browser?: Cypress.Browser;
 
   constructor(
     private readonly logger: Logger,
@@ -57,9 +58,10 @@ export class Plugin {
     browser: Cypress.Browser,
     args: string[]
   ): string[] {
+    this.browser = browser;
     if (!this.isSupportedBrowser(browser)) {
-      throw new Error(
-        `An unsupported browser family was used: ${browser.name}`
+      this.logger.warn(
+        `HAR recording is not supported in this browser: ${browser.name}`
       );
     }
 
@@ -77,6 +79,10 @@ export class Plugin {
   }
 
   public async recordHar(options: RecordOptions): Promise<void> {
+    if (this.browser && !this.isSupportedBrowser(this.browser)) {
+      return;
+    }
+
     await this.closeConnection();
 
     if (!this.addr) {
@@ -99,6 +105,10 @@ export class Plugin {
   }
 
   public async saveHar(options: SaveOptions): Promise<void> {
+    if (this.browser && !this.isSupportedBrowser(this.browser)) {
+      return;
+    }
+
     const filePath = join(options.outDir, options.fileName);
 
     if (!this._connection) {
@@ -130,6 +140,10 @@ export class Plugin {
   }
 
   public async disposeOfHar(): Promise<void> {
+    if (this.browser && !this.isSupportedBrowser(this.browser)) {
+      return;
+    }
+
     await this.networkObservable?.unsubscribe();
     delete this.networkObservable;
 

where the plugin does nothing except warn that HAR recording is not supported when running in those browsers?

That way plugin consumers who run their cypress tests in both supported and unsupported browsers (and are fine with only having HAR recording in supported browsers) wouldn't have to add hacks in setupNodeEvents to conditionally enable the plugin nor manually check the browser before calling recordHar/saveHar.

rmacklin avatar Mar 10 '24 01:03 rmacklin