I don’t have control over code in the site hosting the iFrame. That’s someone else’s site. It’s totally sufficient that I can cause that parent to redirect.
That’s not the root problem. The root problem here is what seems to be a bug in Schedule API Workflow (SAPIW) – while in the workflow editor you can see that it is supposed to report a return value, this action does not (it seems to notify the workflow that it is COMPLETE, when in fact it has only started) and that keeps my workflow from being able to know when all pending workflow actions are complete, and that causes my redirect JavaScript to execute while actions are still pending… leading to the “Leave Site?” dialog.
What’s going on here (which I’m documenting below in great detail for a new bug report about SAPIW) might also explain many similar issues that arise in terms of ensuring synchronous behavior of Bubble workflows when that is required.
We are missing an essential state or two in terms of mimicking the behavior of native Bubble elements. We don’t have a general, programmatic way to know if there are pending workflow actions, for example, except by the tools we are already familiar with (using pause, evaluating the state of return values from workflow steps, etc.
Conversely, not all Bubble actions are well-behaved vis-a-vis our current capabilities to interact with and control them in a workflow.
Schedule API Workflow is one of these. Clearly, it is intended that Schedule API Workflow should report a return value (probably the ID of the scheduled workflow, but since it’s undocumented we can’t know) to signal that it has competed the scheduling (and delay workflow execution if that’s important). But it does not do that. It immediately reports a null value.
Whatever is happening behind the scenes, the net effect is that SAPIW (Step 9) has effectively signaled that its return value is ready for inspection. So Step 10 evaluates that value and puts it into the custom state. We see via Step 11 that the value is null.
There are two things wrong here. First, that Step 10 has executed is supposed to imply that Step 9 (SAPIW) has returned (as Step 10 cannot evaluate the return value until it’s available for inspection). This is clearly not the case, however, as the progress bar is still going. Step 9 has signaled completion prematurely (I think what it actually does is signals that it’s started!).
Second, the value “returned” is null. This shouldn’t surprise us as we know that Step 9 has not in fact competed. So, whatever this return value is supposed to represent, we can’t expect it to make any sense at this point.
(The question remains: What is the return value of SAPIW supposed to represent? The fact that the return value is of type text implies that it’s intended for a unique ID. But again, this is not documented — so I’m just making an assumption here.)
It’s only when we hit these edge cases that we start to see certain capabilities we didn’t know about.
Of course it makes perfect sense that “Open external website” would internally ensure that the redirect would not prematurely leave the page and interrupt pending workflow actions.
Ok, cool. So, my enhanced, custom version of “open external website” (which is just a JavaScript redirect that operates on the app’s parent’s window rather than the app’s window) just needs to wait until pending workflow actions are complete.
Alright, easy-peasey. We’ll just… oh… ummm … hmmm… hey, there’s no way for me to do that.
We know that when we fire a workflow action something will happen and that it will take some amount of time to happen. We also know that — even though we do not receive an event or an explicit notification that an action has competed — we can understand IMPLICITLY that an action has competed by examining its return value.
We understand that, if we request that a downstream action (workflow step) examine the return value of a previous step, we can be assured that that downstream step cannot and will not execute until such time as that return value is actually available for evaluation.
But as we can see, some return values (at least the one from Schedule API Workflow) cannot be trusted. So the presence of that workflow step breaks this workflow in that we no longer know and can no longer control when it will compete.
In fact, both Run JavaScript and Open External Website in my example are called “too early”. However, Open External Website has some internal code that awaits all pending workflow actions before doing the redirect. (So if Open External Website is triggered, the page redirects silently.) If Run JavaScript is triggered, it executes its redirect immediately, causing the “Leave Site?” dialog to appear as the Schedule API Workflow step is not yet complete.
So, in summary, @neerja in support is correct: The “Leave Site?” dialog really does only appear when there are pending workflow actions that might be disrupted if we leave the page. (So for anyone else wondering about this dialog – that’s what’s going on.) I’m asking them to close my submitted bug about “Leave Site”.
However, I’ll be opening a new bug about Schedule API Workflow’s inaccurate reporting of return value.
As far as working around this problem with Run JavaScript: There’s no easy way to tell if there are pending workflow actions in some queue. We do have a second-order hint about this in the Progress Bar. So I suppose one could await executing the redirect function until one finds the Progress Bar is not present on the page.
(As I mentioned previously, the Progress Bar does have a class or an id that one can key off of and I assume this is how Zeroqode’s progress bar plugin works. I don’t think this is the most robust solution as I’m not sure how much I trust the progress bar given that we see some bugs in how workflow actions – at least in the case of SAPIW – can have bugs in terms of reporting their completion, but at the moment this seems like all we have to go on.
A more robust solution would be to have a native Bubble action or state that can report to us the status of the pending workflow queue. This would be a very helpful thing in many applications/use cases!)