jlalmes / trpc-chrome

tRPC adapter for Web Extensions 🧩
https://www.npmjs.com/package/trpc-chrome
MIT License
272 stars 21 forks source link

Question: do you have a recommendation on how to use trpc-chrome with a trpc web server #7

Open firemuzzy opened 1 year ago

firemuzzy commented 1 year ago

Hi @jlalmes, love the idea of having a typesafe communication with background thread.

I am trying to figure out the best way to update my extension to use TRPC throughout. trpc-chrome will give me type safe content scripts to background communication, but I also have the background script communicating with a trpc api server.

Do you have a recommendation on the best way to do this, other than creating another TRPC client in the background tab to make calls to the server? I am trying to avoid duplication but can't think of another way to proxy the call through the background script to the api to preserver the types.

raynirola commented 1 year ago

Best way achieve this is to use monorepo and import router definition from api server in extension. Here is a simple pnpm workspace monorepo, you can replace packages/website with extension.

klaaz0r commented 1 year ago

@firemuzzy did you manage to solve this?

seo-ai-team commented 1 year ago

Best way achieve this is to use monorepo and import router definition from api server in extension. Here is a simple pnpm workspace monorepo, you can replace packages/website with extension.

This isn't what the question is about. The problem is that there is now a second hop before the backend server.

The structure looks like this and IDK what the best setup for it is. Start in content script -> go to background script -> make API call to the backend Backend response -> background script -> response in content script

seo-ai-team commented 1 year ago

Looked into this a bit. I'd love if ChromeHandler had the ability to take another link as a parameter, something like HttpBatchLink. That way we can specify what backend URL we would want to eventually ping