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

WB-530: Add support for connect-web and connect-web protocol #141

Merged
merged 6 commits into from
Oct 26, 2022

Conversation

matt-lewandowski
Copy link
Contributor

@matt-lewandowski matt-lewandowski commented Oct 25, 2022

Support for connect-web

Create a new script that adds a connect web interceptor to the window. This can be used when implementing connect-web clients.

Gotchas

In order to upgrade this plugin to manifest V3, we will need to make some breaking changes. This includes not injecting scripts into browsers as a string.
V3 guards against this, so we will need to inject it as a shared js file. I have done so with this new script, but this causes an issue where sometimes the script loads after the app. We don't have control over the order that these scripts load.

The solution is to attempt to use the interceptor if it exists on the client, and if it doens't then watch for our custom event to see if it is ready again. For connect web this can be done like this.

// __CONNECT_WEB_DEVTOOLS__ is loaded in as a script, so it is not guaranteed to be loaded before your code.
const interceptors: Interceptor[] = window.__CONNECT_WEB_DEVTOOLS__ !== "undefined" ?
  [window.__CONNECT_WEB_DEVTOOLS__]
  : [];
// To get around the fact that __CONNECT_WEB_DEVTOOLS__ might not be loaded, we can listen for a custom event,
// and then push the interceptor to our array once loaded.
window.addEventListener("connect-web-dev-tools-ready", () => {
  if (typeof window.__CONNECT_WEB_DEVTOOLS__ !== "undefined") {
    interceptors.push(window.__CONNECT_WEB_DEVTOOLS__);
  }
});
// Now we can use the interceptors in our transport
const transport: Transport = createGrpcWebTransport({
  baseUrl: getApiHostname(),
  interceptors,
});

We will have to migrate the grpc-web script to do the same thing, later down the line, otherwise, chrome will take the extension down.

@gtiminskis-sc
Copy link

We will have to migrate the grpc-web script to do the same thing, later down the line, otherwise, chrome will take the extension down. do we know when that will happen?

Copy link

@gtiminskis-sc gtiminskis-sc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really interesting stuff, code looks good. Will give this a try on the other PR

@matt-lewandowski
Copy link
Contributor Author

We will have to migrate the grpc-web script to do the same thing, later down the line, otherwise, chrome will take the extension down. do we know when that will happen?

https://developer.chrome.com/docs/extensions/mv3/mv2-sunset/

It looks like they are going to start making progress at the start of 2023, and will totally remove all v2 by 2024. We should start making progress towards this sooner rather then later though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants