kakaroto / Beyond20

D&D Beyond Character Sheet Integration in Roll20
GNU General Public License v3.0
484 stars 141 forks source link

Support Roll20 as a Discord Activity #1109

Open rileydutton opened 3 months ago

rileydutton commented 3 months ago

Hey there!

Roll20 is coming to Discord as an Activity. As part of that we are taking a look at popular extensions that Roll20 users install and seeing what needs to be done to support the Activity version. In particular, it doesn't seem possible to use the messaging feature to send messages between tabs since the Activity runs as a nested iFrame in a different domain from the parent tab (this is a Discord security feature and applies to all Activities).

Therefore, I put together this quick PR that adds support for using a content port to communicate with the Discord Activity version. It only uses this method if the extension detects that it's running in an Activity, otherwise it uses the current message passing method.

The one drawback to this is the "filter to a specific tab" feature really isn't supported for the Activity (if you pick a specific tab it just won't work), but I think that's an acceptable tradeoff to get this working.

Let me know if this makes sense or if I can help work on a different approach that would work well for the extension. And thanks for providing this resource to the tabletop gaming community!

rileydutton commented 3 months ago

Is there a staging build of the new activity to use for testing?

I guess a bit of new documentation to tackle as well, so I can kill two kobolds with one stone this weekend

@jtbg There is an internal Beta going on right now that I can get you access to, if you let me know your Roll20 account email. You can just email me at riley@roll20.net.

HaarisQureshi commented 3 months ago

Have given @jtbg's build a test, does not seem to be sending Rolls to the Discord activity, either to the app or via browser

kakaroto commented 3 months ago

Hi @rileydutton! Welcome to the Beyond20 contributors list! 😁

Thanks for sending this PR, I saw the announcement a few days ago on your blog and was excited by the idea. I think the discord activity is a great feature and I can't wait to give it a try. I'll send you an email to get beta access so I can test this out.

I've had a quick look at the code, it looks good, I have a couple of suggestions that I want to try (and see if they're viable) before I do a PR review. The main issue I have with this though is the addition of the new host to the manifest. Unfortunately, as we've discovered when we added astral tabletop support a couple of years back, changing those permissions causes the extension to get automatically disabled for all users, until they manually go to "manage extensions" and approve the new permissions. Because of that, I believe we lost half our userbase and it caused a lot of user confusion. Because of that, I decided not to add any new domains to the manifest for the time being. I might be wrong with how exactly chrome does it, but I don't want to tempt fate.

What we've implemented instead is the ability to prompt the user at runtime for optional permissions as needed, so I think for this instance, it's going to be better to do a user prompt with an optional permission so it doesn't disable the extension, so I want to add that alternative way instead for the discord activity. Once I have beta access to it, I'll give it a try and see how to make it work as smoothly as possible for the users. Thanks again for the contribution, and congrats on the new Roll20<->Discord feature!

jtbg commented 3 months ago

I might be wrong with how exactly chrome does it, but I don't want to tempt fate.

Not wrong at all, this would require the user to explicitly re-enable it.


1. Technical demo of chrome flagging the update https://github.com/kakaroto/Beyond20/assets/10716475/ba2aa7b5-6190-4df4-86bc-298d297cd741
2. UX demo of public-facing view post-update https://github.com/kakaroto/Beyond20/assets/10716475/0247be72-42f5-42db-8c37-f3b6dfe0131b ![UX-demo-gif](https://developer.chrome.com/static/docs/extensions/develop/concepts/permission-warnings/image/example-an-extension-is-6772580db51de.gif)
rileydutton commented 3 months ago

Hey all,

Thanks for taking the time to look at this! Appreciated.

Really however you all want to handle it re: the permissions is fine, that makes sense. I did notice there is a part of the options dialog that shows up if it detects that permissions don't exist for the current domain, but that was detecting "discord.com" instead of the "1199271093882589195.discordsays.com" (again due to the whole nested iframes issue). But if there's a way to prompt for permissions on the correct domain the first time you launch the Activity (or however you want to do it) that should work fine!

Really I just wanted to get this process started and at least attempt to provide some working code, but as you all get in and check it out I'm sure you know better than me what changes need to be made :-) But let me know if I can help.

kakaroto commented 1 month ago

Update: I did some testing/investigating today, and yeah, removing the permission from the manifest is going to make it a bit challenging because of the all_frames: true part. We can't inject into 1199271093882589195.discordsays.com unless the tab itself has that URL, so I'd need to add a content-script on discord.com and have that look for the iframe and inject the roll20 script into it. I think that's the best/only way to do it.

Note that would also allow us to have the popup settings work if we can have the discord.com content script act as roll20 basically, when the iframe is there. Will see how we can solve that.

I'll take a stab at getting that to work soon (hopefully 🤞)