Problems with defold-sharing

Hi i’ve been using defold-sharing on 2 of my projects. And im sure I had it working. But just tried it now and it seems to be broken.

this is my code:

	screenshot.png(function(self, img, w, h)
					share.image(img, " Lorem ipsum etc etc", "score.png")

Am I doing something wrong? any clues as to what may be the issue?

How? Does it crash? Do you get an error?

No it dosn’t crash, the rest of game keeps working.
I only ever got it to work in html5 in android. not sure how to check the log there.
In html5 on Pc it says:

Sharing Error: TypeError: Cannot read properties of null (reading ‘1’)

Ok, I think it crashes here:

Can you make sure that img in the screenshot.png callback is not nil?

something like this?

				screenshot.png(function(self, img, w, h)
					if not img == nil then
						share.image(img, "Lorem ipsum etc etc", "score.png")
						print("img is nil")

im sorry im not sure I understand

Exactly. What happens if you try to check img like you do in the code you shared? Is it nil?

yeah it prints some strange characters but it does seem like it is nill.
here is an image of the console:

Oh, one thing I noticed in your code (which you have removed now) was this:

if not img == nil then

I don’t think it evaluates as you expect it to. The Lua operator precedence will evaluate not before ==:

What you want to write is this:

if not (img == nil) then


if img ~= nil then
1 Like

woops thanks for the clarification!
fixed code to this:

                print("sharing image")
				screenshot.png(function(self, img, w, h)
					if img ~= nil then
						share.image(img, "Mira sa meva puntuacio amb es joc de l'EMT!\nFes click aqui per jugar", "score.png")
						print("img is nil")

now im back to the initial error message i got before:

Hmm, ok, so the image is correct. Which version of defold-sharing are you using? What do you have in game.project dependencies?

I believe i am using the last one.

Ok, could you please create a ticket in defold-sharing and include a minimal project I can use to investigate this issue?

Okay, I submitted a ticket. Hope it’s what you need! :slight_smile:

1 Like

Hi, so I saw the update to the library but I still can’t get it to work.
No I get: “Sharing Error: NotAllowedError: Permission denied”

Have you managed to get it working?

Yes it works on macOS when testing in Safari. Firefox and Chrome doesn’t work (which seems to be according to spec). Perhaps it’s possible to request a sharing permission or something?

Are you sure its acording to spec? Mdn web docs share the Navigator.share example in this page works fine on chrome and firefox. No need to request permission.

Nope. Not on macOS in latest Chrome:

The same on Firefox. On macOS it only works on Safari.

I see… it works fine on windows and android. Seems to be a macOS issue.
I updated the minimal project and now get the permission error:

I believe this is an issue with defold-sharing as the Mdn web docs share works fine.

I just tested the min project on a collegues mac using safari and I get the same permission error. Mdn web docs share both examples work for me, including the sharing .png example. So the permission error should not be triggering since .png is an allowed file type in the spec.

What if you modify your sample app to share a text instead of an image? This will make it work the same way as the MDN example.