#I'm getting an error where the

1 messages · Page 1 of 1 (latest)

ruby belfry
raven grotto
#

Noted, thanks Kenji!

raven grotto
#

@ruby belfry Even after adding my own trial_token, I still get the same issue

#

Is it possible to use more than one trial token at the same time? I'm using the other one still to ensure the prompt API is still working

woven wing
raven grotto
#

Getting the same error as before where the translator API is not supported

woven wing
#

Can you please confirm that the extension's key matches the one for which you've registered the origin trial?

These are the keys I've used for the sample extension when testing this:

  "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvf0O/bR3JULoj6dOpG7sDif4BNVgootUIfSybh2a7jX47BglfZFNH/aRUgDjNtcTBPinXdGbljMVIudQ7w6LiwVq9b1Ht6ZXFVtHTKOsDWtVh/rVKE/AGue9eQ7xCncHFl4zLJUaDRUIRqe5zvjHtaMr8p92I3c/6k43LmTUp1QHz0NooDJRYKRPLS77YVDX8hZc2yopIH5NIY25Ned3wxZ/NWV70GZkYqFRN+UzvMS8bJUEY23L1AMSX7YQjMThY0BCZ/MBLo8UBLs8vN11EphMpLxnBhF2Zwwj2sCPR0jn0ev8HYCtKmGx8nzOl79oK24RFIsW8YWFB2fd28fBLwIDAQAB",
  "trial_tokens": ["AtnV2DsKHgyQnmjqSUeZF4t0ahWN3VHNlY7ikMXZkFaEvMwXQaOm/hgrO5BwUzuxwD3LrrcVMgqz8oiDNPbJHgkAAABveyJvcmlnaW4iOiJjaHJvbWUtZXh0ZW5zaW9uOi8vYWhpaWZrb2RnbWlmcGNnbmRja3BwaW1lY25wa3BkbGwiLCJmZWF0dXJlIjoiVHJhbnNsYXRpb25BUEkiLCJleHBpcnkiOjE3NTMxNDI0MDB9",
    "Aozzz6KfHYqh8q5x+Khse27nSp8YM7Tftv6XZhNO7lgYcP5uQxxBEpMfRhiFbYJV+yJl1fDNzvtao7FswtZGIgQAAAB4eyJvcmlnaW4iOiJjaHJvbWUtZXh0ZW5zaW9uOi8vYWhpaWZrb2RnbWlmcGNnbmRja3BwaW1lY25wa3BkbGwiLCJmZWF0dXJlIjoiQUlQcm9tcHRBUElGb3JFeHRlbnNpb24iLCJleHBpcnkiOjE3NjA0ODYzOTl9"
  ],
raven grotto
#

yup I confirm they match but still no luck

#
const browserSupportsAPI = (util, apiName) => {
  if (util in self && apiName in self.ai) {
    return true;
  } else {
    console.log(
      `${apiName} not supported on browser. Unable to run ${apiName} API`
    );
    return false;
  }
};
#
if (!browserSupportsAPI('translation', 'createTranslator'))
    return noTranslation;
#

It fails at this part ^^

woven wing
#

You're checking for the wrong namespace:

      const canTranslate = await translation.canTranslate({
raven grotto
#

Oh my, you are correct, I tried making all my code completely reusable across other APIs and missed a spot, thanks a bunch Sebastian!

#

With the correction, I still seem to be getting the same issue, is there another step I possibly missed? I confirm I have the same key value and it's enabled in google canary

woven wing
# raven grotto With the correction, I still seem to be getting the same issue, is there another...

This is my code:

    if ('translation' in self && 'createTranslator' in self.translation) {
      console.log('translating...');
      const canTranslate = await translation.canTranslate({
        sourceLanguage: 'en',
        targetLanguage: 'es',
      });
      console.log('translation status: ', canTranslate);
      const translator = await self.translation.createTranslator({
        sourceLanguage: 'en',
        targetLanguage: 'es',
      });
      response = await translator.translate('Where is the next bus stop, please?');
    }
raven grotto
#

I have similar code, maybe it's a config issue on my side

woven wing
#

Do you run it in a service worker?

raven grotto
#

yup I do

#

Also, I just tried copying your code to test it and get a different error so I must have a typo on my side, working on spotting it

woven wing
#

that's it. It's not available there (I've been running it in a side panel). Try running it in an offscreen document.

raven grotto
#

Ah I see! Interesting, I never thought of that, I run all my API calls in a service worker to ensure the extension is persistent

#

Will give it a shot for running it in an offscreen document

#

thanks again Sebastian, life saver 🙂

woven wing
raven grotto
raven grotto
#
  1. It doesn't work with the French language (fr) for me
  2. Also in this screenshot, there's a typo, I believe it should be translation.ondownloadprogress and not translator.ondownloadprogress
#

Other than that, I got it working through trial and error, thanks a bunch for your help