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

SignalR | Electron | CookieJar is creating issue with Electron .Net App + Angular 14 #52656

Open
1 task done
IamAgrawal opened this issue Dec 8, 2023 · 7 comments
Open
1 task done
Labels
area-signalr Includes: SignalR clients and servers

Comments

@IamAgrawal
Copy link

IamAgrawal commented Dec 8, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I am using Electron.Net as backend and Angular as frontend to initiate System App. When I am trying to setup connection with HubConnectionBuilder, I am getting issue:

CookieJar is not a constructor

For Further research, I got to realize that this issue arises due to its requirement of fetch-cookie in DefaultHttpClient.ts file in @microsoft/signalR package. For now, I have used downgraded version of it, but will be looking for solution with latest version 8.0.0.
My frontend code is like below:

this.hubConnectionBuilder = new HubConnectionBuilder()
.configureLogging(LogLevel.Information)
.withUrl("http://localhost:4200/ABCD")
.build()

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

6.0.414

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-signalr Includes: SignalR clients and servers label Dec 8, 2023
@IamAgrawal IamAgrawal changed the title CookieJar is creating issue with Election .Net App + Angular 14 SignalR | Election | CookieJar is creating issue with Election .Net App + Angular 14 Dec 8, 2023
@IamAgrawal IamAgrawal changed the title SignalR | Election | CookieJar is creating issue with Election .Net App + Angular 14 SignalR | Electron | CookieJar is creating issue with Electron .Net App + Angular 14 Dec 8, 2023
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@universal
Copy link

i ran into a similar issue with an electron app when upgrading from signalr 6 to 8.

after adding

  "resolutions": {
    "tough-cookie": "4.1.3"
  }

to my package.json it appears to be working again!

During debugging this I noticed that the call to CookieJar.getCookieString(...) had the callback and the url in a different order, than the code seemed to expect it.
Without the additional resolution restriction in my project (lerna monorepo) I end up with multiple different versions of tough-cookie and something along the way goes haywire...

It appears that somehow the wrong (old) version gets required...

Output with the resolution restriction

yarn why tough-cookie
yarn why v1.22.19
[1/4] Why do we have the module "tough-cookie"...?
[2/4] Initialising dependency graph...
warning Resolution field "tough-cookie@4.1.3" is incompatible with requested version "tough-cookie@^3.0.1"
warning Resolution field "tough-cookie@4.1.3" is incompatible with requested version "tough-cookie@~2.5.0"
warning Resolution field "tough-cookie@4.1.3" is incompatible with requested version "tough-cookie@^2.3.3"
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "tough-cookie@4.1.3"
info Reasons this module exists
   - "_project_#jest-environment-jsdom#jsdom" depends on it
   - Hoisted from "_project_#jest-environment-jsdom#jsdom#tough-cookie"
   - Hoisted from "_project_#@app#infrastructure#@microsoft#signalr#fetch-cookie#tough-cookie"
   - Hoisted from "_project_#jest-jasmine2#jest-runtime#jest-config#jest-environment-jsdom#jsdom#tough-cookie"
   - Hoisted from "_project_#jest-jasmine2#jest-runtime#jest-config#jest-environment-jsdom#jsdom#request-promise-native#tough-cookie"
   - Hoisted from "_project_#@app#infrastructure#@jest-runner#electron#jest-runner#jest-config#jest-environment-jsdom#jsdom#tough-cookie"
   - Hoisted from "_project_#jest-jasmine2#jest-runtime#jest-config#jest-environment-jsdom#jsdom#request#tough-cookie"
info Disk size without dependencies: "160KB"
info Disk size with unique dependencies: "784KB"
info Disk size with transitive dependencies: "828KB"
info Number of shared dependencies: 5
Done in 0.62s.

Output without the additional resolution restriction:

yarn why tough-cookie
yarn why v1.22.19
[1/4] Why do we have the module "tough-cookie"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "tough-cookie@2.5.0"
info Has been hoisted to "tough-cookie"
info Reasons this module exists
   - "workspace-aggregator-0efcd8c3-fafa-44cd-9736-47bb72ea7074" depends on it
   - Hoisted from "_project_#jest-jasmine2#jest-runtime#jest-config#jest-environment-jsdom#jsdom#request-promise-native#tough-cookie"
   - Hoisted from "_project_#jest-jasmine2#jest-runtime#jest-config#jest-environment-jsdom#jsdom#request#tough-cookie"
info Disk size without dependencies: "108KB"
info Disk size with unique dependencies: "632KB"
info Disk size with transitive dependencies: "632KB"
info Number of shared dependencies: 2
=> Found "jsdom#tough-cookie@4.1.3"
info This module exists because "_project_#jest-environment-jsdom#jsdom" depends on it.
info Disk size without dependencies: "136KB"
info Disk size with unique dependencies: "760KB"
info Disk size with transitive dependencies: "804KB"
info Number of shared dependencies: 5
=> Found "fetch-cookie#tough-cookie@4.1.3"
info This module exists because "_project_#@app#infrastructure#@microsoft#signalr#fetch-cookie" depends on it.
info Disk size without dependencies: "136KB"
info Disk size with unique dependencies: "760KB"
info Disk size with transitive dependencies: "804KB"
info Number of shared dependencies: 5
=> Found "jest-jasmine2#tough-cookie@3.0.1"
info Reasons this module exists
   - "_project_#jest-jasmine2#jest-runtime#jest-config#jest-environment-jsdom#jsdom" depends on it
   - Hoisted from "_project_#jest-jasmine2#jest-runtime#jest-config#jest-environment-jsdom#jsdom#tough-cookie"
info Disk size without dependencies: "112KB"
info Disk size with unique dependencies: "652KB"
info Disk size with transitive dependencies: "652KB"
info Number of shared dependencies: 3
=> Found "@jest-runner/electron#tough-cookie@3.0.1"
info Reasons this module exists
   - "_project_#@app#infrastructure#@jest-runner#electron#jest-runner#jest-config#jest-environment-jsdom#jsdom" depends on it
   - Hoisted from "_project_#@app#infrastructure#@jest-runner#electron#jest-runner#jest-config#jest-environment-jsdom#jsdom#tough-cookie"
info Disk size without dependencies: "112KB"
info Disk size with unique dependencies: "652KB"
info Disk size with transitive dependencies: "652KB"
info Number of shared dependencies: 3
Done in 0.58s.

@universal
Copy link

universal commented Feb 21, 2024

adding an explicit dependency to "tough-cookie": "^4.1.3" in the electron project appears to also be working. (lerna monorepo...)

adding trace log if someone ends up googling for this error...

@app/infrastructure: [2024-02-21T16:43:22.245Z] Debug: Starting HubConnection.
@app/infrastructure: [2024-02-21T16:43:22.245Z] Debug: Starting connection with transfer format 'Text'.
@app/infrastructure: [2024-02-21T16:43:22.245Z] Debug: Sending negotiation request: https://some-domain.non-existent/somehub/negotiate?negotiateVersion=1.
@app/infrastructure: [2024-02-21T16:43:22.246Z] Debug: HubConnection failed to start successfully because of error 'Error: Failed to complete negotiation with the server: TypeError: Cannot read properties of undefined (reading 'secure')'.
@app/infrastructure: [2024-02-21T16:43:22.246Z] Warning: Error from HTTP request. TypeError: Cannot read properties of undefined (reading 'secure').
@app/infrastructure: [2024-02-21T16:43:22.246Z] Error: Failed to complete negotiation with the server: TypeError: Cannot read properties of undefined (reading 'secure')
@app/infrastructure: [2024-02-21T16:43:22.246Z] Error: Failed to start the connection: Error: Failed to complete negotiation with the server: TypeError: Cannot read properties of undefined (reading 'secure')

@danluc
Copy link

danluc commented Feb 28, 2024

adding an explicit dependency to "tough-cookie": "^4.1.3" in the electron project appears to also be working. (lerna monorepo...)

adding trace log if someone ends up googling for this error...

@app/infrastructure: [2024-02-21T16:43:22.245Z] Debug: Starting HubConnection.
@app/infrastructure: [2024-02-21T16:43:22.245Z] Debug: Starting connection with transfer format 'Text'.
@app/infrastructure: [2024-02-21T16:43:22.245Z] Debug: Sending negotiation request: https://some-domain.non-existent/somehub/negotiate?negotiateVersion=1.
@app/infrastructure: [2024-02-21T16:43:22.246Z] Debug: HubConnection failed to start successfully because of error 'Error: Failed to complete negotiation with the server: TypeError: Cannot read properties of undefined (reading 'secure')'.
@app/infrastructure: [2024-02-21T16:43:22.246Z] Warning: Error from HTTP request. TypeError: Cannot read properties of undefined (reading 'secure').
@app/infrastructure: [2024-02-21T16:43:22.246Z] Error: Failed to complete negotiation with the server: TypeError: Cannot read properties of undefined (reading 'secure')
@app/infrastructure: [2024-02-21T16:43:22.246Z] Error: Failed to start the connection: Error: Failed to complete negotiation with the server: TypeError: Cannot read properties of undefined (reading 'secure')

where did you put this?
Could you show the complete path?
I have the same problem

@universal
Copy link

where did you put this? Could you show the complete path? I have the same problem

the log level can be set in the connection constructor like this:

this.connection = new signalR.HubConnectionBuilder()
      .withAutomaticReconnect({
        nextRetryDelayInMilliseconds: () =>
          1000 + (Math.random() * 100)
      })
      .configureLogging(signalR.LogLevel.Trace)
      .withUrl(this.options.url.href)
      .build()

and tough-cookie dependency is added to the package.json, for me in packages/infrastructure/package.json

...
  "dependencies": {
    "@app/services": "^1.3.0",
    "@microsoft/signalr": "^8.0.0",
    "electron-unhandled": "^4.0.1",
    "tough-cookie": "^4.1.3"
  },
...

@danluc
Copy link

danluc commented Feb 29, 2024

onde você colocou isso? Você poderia mostrar o caminho completo? Eu tenho o mesmo problema

o nível de log pode ser definido no construtor de conexão assim:

this.connection = new signalR.HubConnectionBuilder()
      .withAutomaticReconnect({
        nextRetryDelayInMilliseconds: () =>
          1000 + (Math.random() * 100)
      })
      .configureLogging(signalR.LogLevel.Trace)
      .withUrl(this.options.url.href)
      .build()

e a dependência de cookies resistentes é adicionada ao package.json, para mim empackages/infrastructure/package.json

...
  "dependencies": {
    "@app/services": "^1.3.0",
    "@microsoft/signalr": "^8.0.0",
    "electron-unhandled": "^4.0.1",
    "tough-cookie": "^4.1.3"
  },
...

does not work,
but thanks for the help

@danluc
Copy link

danluc commented Mar 1, 2024

where did you put this? Could you show the complete path? I have the same problem

the log level can be set in the connection constructor like this:

this.connection = new signalR.HubConnectionBuilder()
      .withAutomaticReconnect({
        nextRetryDelayInMilliseconds: () =>
          1000 + (Math.random() * 100)
      })
      .configureLogging(signalR.LogLevel.Trace)
      .withUrl(this.options.url.href)
      .build()

and tough-cookie dependency is added to the package.json, for me in packages/infrastructure/package.json

...
  "dependencies": {
    "@app/services": "^1.3.0",
    "@microsoft/signalr": "^8.0.0",
    "electron-unhandled": "^4.0.1",
    "tough-cookie": "^4.1.3"
  },
...

I downgraded @microsoft/signalr 8 to 6.0.1 and it worked

@reworc
Copy link

reworc commented May 17, 2024

I have a similar issue after upgrading to version 8.0.0 (Angular v17 with ASP.NET mono repo) (cf. https://github.com/visualengineers/reflex)
The issue only arises when packaging the app with Electron.NET, running angular in dev environment works.
For me, only downgrading to Version 6.0.1 solved the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-signalr Includes: SignalR clients and servers
Projects
None yet
Development

No branches or pull requests

5 participants