SafetyCulture / grpc-web-devtools

Chrome & Firefox Browser extension to aid gRPC-Web development

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make use of grpc-web interceptor

jvmlet opened this issue · comments

Now, when grpc-web officially supports interceptors , would be great to see this extension uses them.

BTW, improbable also supports interceptors, so all users might benefit from this great dev tool.

Yea; this is something that I would like to get to doing at some point. Happy for PRs if someone has the time to look into this?

pull request for interceptors #79

merged this change into my fork's master and updated the readme to reflect the change. I'm dropping a link here for anyone that finds this and wants to use native gRPC-Web interceptors:
https://github.com/jrapoport/grpc-web-devtools

@jrapoport So does your version work with https://github.com/improbable-eng/grpc-web? If so, do you need to do anything to make sure that the browser has a specific version of devtools (which supports one client library over the other) installed?

no clue. it was written for https://github.com/grpc/grpc-web interceptors. the version i wrote isn't published so you have to install manually and disable other versions.

it might work with improbable interceptors if they are functionally the same, but i've never tried it.

The following code works for me for improbable-eng

import { grpc } from '@improbable-eng/grpc-web'

...

grpc.unary(methodDescriptor, {
        request: request,
        host: backendURL,
        metadata: new grpc.Metadata(metadata),
        onEnd: res => {
          const { status, statusMessage, headers, message, trailers } = res

          window.postMessage({
            type: '__GRPCWEB_DEVTOOLS__',
            method: methodDescriptor.service.serviceName + '/' + methodDescriptor.methodName,
            methodType: 'unary',
            request: request.toObject(),
            response: message.toObject(),
          }, '*')
       }
    }
 )   

Created this PR with several lines of code to fix this issue.