WICG / digital-goods

Other
50 stars 28 forks source link

Better testing/debugging support #33

Open phoglenix opened 3 years ago

phoglenix commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 6 months ago

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 commented 6 months ago

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

rsolomakhin commented 6 months ago

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