Skip to content

Commit

Permalink
Improve redirects in SDKs
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Feb 2, 2025
1 parent 2ee3ad2 commit 652fd1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sdk/go/execute-script-sugar.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (sse *ServerSentEventGenerator) Redirectf(format string, args ...any) error
}

func (sse *ServerSentEventGenerator) Redirect(url string, opts ...ExecuteScriptOption) error {
js := fmt.Sprintf("window.location.href = %q;", url)
js := fmt.Sprintf("setTimeout(() => window.location.href = %q)", url)
return sse.ExecuteScript(js, opts...)
}

Expand Down
9 changes: 9 additions & 0 deletions sdk/php/src/ServerSentEventGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ public function executeScript(string $script, array $options = []): void
$this->sendEvent(new ExecuteScript($script, $options));
}

/**
* Redirects the browser to the provided URI.
*/
public function redirect(string $uri, array $options = []): void
{
$script = 'setTimeout(() => window.location = "' . $uri . '")';
$this->executeScript($script, $options);
}

/**
* Sends an event.
*/
Expand Down

0 comments on commit 652fd1e

Please sign in to comment.