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

Better testing/debugging support #33

Open
phoglenix opened this issue Sep 13, 2021 · 17 comments
Open

Better testing/debugging support #33

phoglenix opened this issue Sep 13, 2021 · 17 comments

Comments

@phoglenix
Copy link
Collaborator

A common piece of origin trial feedback is that the API is difficult to test/debug. It requires a deployed instance of the app to really see if things work. Ideally we could make this easier somehow.

@mikecann
Copy link

mikecann commented Sep 21, 2021

Ye I have to say its REALLY painful at the moment, I am struggling even to just get the getDigitalGoodsService API to show up despite doing all the chrome://flags AND origin trial dance :(

Using https://github.com/PEConn/beer as an example, it should just work if you serve it locally right?

@phoglenix
Copy link
Collaborator Author

Just an idea: would it be helpful if you could get a dummy Digital Goods service object where all the methods returned no data?

@phoglenix
Copy link
Collaborator Author

Re: https://github.com/PEConn/beer - no, it needs to be in a TWA context (installed from the Play store) to work with the Play payment method. The CrOS and Android backends rely on the Android bits to complete method calls.

The getDigitalGoodsService method should exist on any https site if you have the "Experimental Web Platform Features" flag on or if the site has a valid OT token.

@mikecann
Copy link

mikecann commented Sep 21, 2021

The getDigitalGoodsService method should exist on any https site if you have the "Experimental Web Platform Features" flag on or if the site has a valid OT token.

So this is true ONLY if you are running in a TWA context?

So just for my understanding this means to test Digital Goods one must do the following:

  1. Build and publish site to a public domain (for example https://github.com/PEConn/beer would be published to https://beer.com)
  2. beer.com must have a service worker installed so it can be a valid PWA
  3. use bubblewrap to turn it into a TWA
  4. create an app and go thorugh all that process in Google Play
  5. create a release and push to internal testers
  6. internal testers download the app on an CrOS device using the Play Store
  7. Enable the various debug "Experimental Web Platform Features" flags on your CrOS device
  8. The API should now be available for testing

Is all the above correct?

Then if you want to make another change and test you have to deploy your site to beer.com and reload the CrOS app, theres no way to test it locally, it MUST be published?

@phoglenix
Copy link
Collaborator Author

The getDigitalGoodsService method should exist on any https site if you have the "Experimental Web Platform Features" flag on in your browser or if the site has a valid OT token.

No other context/setup is required for the method to exist.

However, to actually get a valid Play DG service object when calling getDigitalGoodsService, you need a TWA context. I'm not sure it has to be a public site or a valid PWA, but it does need to be a TWA in the Play store.

@mikecann
Copy link

mikecann commented Sep 21, 2021

No other context/setup is required for the method to exist.

I have followed the instructions exactly listed here: https://developer.chrome.com/docs/android/trusted-web-activity/receive-payments-play-billing/#on-a-chrome-os-device.

I am on the Dev channel of CrOS, I have enabled the flags and STILL no API.

I can only conclude that you MUST have the browser running in a TWA context for the API to show..

Edit: I just tried opening the console on https://google.com and typing window.getDigitalGoodsService and BOOM it shows. I flip back to my locally hosted beer url and I get undefined.. Perhaps it only works in a https context?

@phoglenix
Copy link
Collaborator Author

Yes, https + "Experimental Web Platform Features" flag are the requirements for the method to exist.
But it won't return a Play-backed DG service instance unless you're in a TWA context.
This could certainly be better documented. Feel free to file an issue or send a PR to improve that help article you linked (see the "Improve Article" link at the bottom).

If you have ideas about how debugging could be more clear in the API itself, please let me know here.

@mikecann
Copy link

mikecann commented Sep 21, 2021

I think it would be nice if you could do something with the DevTools such as the integration you get with service workers:

image

I will submit a request to update that article

@MrVibe
Copy link

MrVibe commented Jan 10, 2022

I have been struggling this for months now. The window.getDigitalGoodsService always appears as undefined. The App is already published on Google playstore with inApp products. [ app.wplms.io ].

@phoglenix
Copy link
Collaborator Author

@MrVibe this API is still in Origin Trial. You can test locally by enabling Chrome flags as mentioned in the chrome dev article or you can sign up for the DGAPI v2 origin trial and add the token on your site.

@MrVibe
Copy link

MrVibe commented Jan 22, 2022

Yes using digital goods api v2 , also verified the token here : https://googlechrome.github.io/OriginTrials/check-token.html
yes, it is working now. Thanks for help.

@anshumansahu143
Copy link

anshumansahu143 commented Jan 22, 2022

Hi we got this enabled but getting error "unsupported context" running this small snippet :

`const PAYMENT_METHOD = "https://play.google.com/billing";
async function getDetails(sku) {

try {
if (window.getDigitalGoodsService) {

  service = await window.getDigitalGoodsService(PAYMENT_METHOD); ERROR APPEARING HERE

} else {

console.log("window doesn't have getDigitalGoodsService.");
}
} catch (error) {
console.log('err',error); DEBUG MESSAGE GIVING : "DOMException: unsupported context"
}
}
getDetails('50_credits');
`

HOW to detect what might be wrong here ?

app published to playstore in beta tester.

@phoglenix
Copy link
Collaborator Author

Note for this issue: perhaps we can provide more fine-grained exception messages here?

"Unsupported context" means that something is wrong with your app (TWA) context. Either you're not in Android/CrOS (unlikely), or your TWA package isn't installed for the current URL, or you aren't running as an app (in an app window).

@anshumansahu143
Copy link

Yes this : or you aren't running as an app (in an app window).
was the case in our app, the url bar was appearing in the app and we have not cofigured the assetslinks.json file properly .
The key point was to clear up the chrome browser cache after configuring the assetslinks.json file.

@vflam
Copy link

vflam commented May 31, 2024

Hello, I am trying to get this to work but getDigitalGoodsService is undefined even from within a TWA installed from google store internal tests. It doesn't appear in origin trials anymore so I assume this is not necessary. But it just won't work. Was this API deleted? Any research I do leads to stuff from 2022 or older...

@phoglenix
Copy link
Collaborator Author

It is still expected to work. You need to be on an HTTPS page on Android or ChromeOS for getDigitalGoodsService to be available.

@rsolomakhin
Copy link
Collaborator

You may want to enable chrome://flags/#enable-debug-for-store-billing to bypass a check:

This flag removes the restriction that the TWA has to be installed from the app-store

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

No branches or pull requests

6 participants