I’m attempting to follow a tutorial to publish an anvil app as a farcaster mini app:
I have the js libary loaded via the app’s import map and all seems fine until I call the ready
function mentioned in the guide page above.
At that point, I get a skulpt runtime error.
Here’s an MWE showing what happens:
I’m guessing the promise from that function eventually resolves to something a bit obscure. Is there some way around this?
EDIT
Today’s task - wrapping that call in a js function of my own and calling that from python. I’ll report back later…
1 Like
thanks for the clone
I think i’ve seen something similar before (probably on the forum somewhere)
You’re right the object being returned is obscure
the .ready
function being returned is a proxy function
and is politely answering certain questions as "yes"
when we interrogate it to determine what to do with it in python.
We use javascript introspection and ask it questions like
Q. Do you have this attribute?
A. Yes
Ok so you must be a python object
… Proceeds to treat it as a python object
Explosions start, when it keeps answer yes to all questions asked of it
A way to deal with this for now
<script type="module">
// in native libraries
import { sdk } from "@farcaster/frame-sdk";
window.sdk = {
actions: {
ready: () => sdk.actions.ready(),
// extend as you need
},
};
</script>
# Form1.py
from anvil.js import window
# _frame = anvil.js.import_from("@farcaster/frame-sdk")
sdk = window.sdk
print(dir(sdk.actions))
moved to bug reports
we’ll see if we can get this one fixed
2 Likes
Ha! We must have been typing at the same time! That’s pretty much what I decided to try today.
Thanks for looking at it.
2 Likes
I see the farcaster link has a few hits. If anyone else happens to be on there, I’m ‘meatballs’. Here’s my profile:
Feel free to say hi!
I’m still seeing problems even using the workaround.
I’ve added the script to native libs and amended the form’s code to:
from ._anvil_designer import Form1Template
import anvil.js
anvil.js.report_all_exceptions(True)
sdk = anvil.js.window.sdk
class Form1(Form1Template):
def __init__(self, **properties):
self.init_components(**properties)
def form_show(self, **event_args):
print("hello")
sdk.actions.ready()
print("world")
When I run it, I now don’t get any errors, but I also never see the last print happening.
Updated MWE:
try running it in a new tab rather than in the iframe
my guess is something is preventing ready
from completing when it’s being run inside an iframe
1 Like
Oh good grief. You’d think I’d know that one by now.
That does indeed fix the problem when the app runs normally - but when it runs as a farcaster mini app, I get the same problem as within the IDE. It’s not an Iframe within the farcaster client (warpcast) as far as I can tell.
update:
I now have a ‘hello world’ app working as a farcaster mini app - but only on mobile. On desktop, nothing happens at all. Feels like a farcaster problem to me at this point.
Gotcha!!
My mistake - warpcast on desktop does use an iframe. I just needed to allow embedding and it’s working fine there too now (with the workaround).
1 Like