ionic-team / ionic-team/capacitor-os-inappbrowser

Feature Request: Add executeScript method for JavaScript injection

Open
#103 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
13
Forks
15
PR merge metrics
No merged PRs in 30d

Description

Currently, the @capacitor/inappbrowser plugin lacks the ability to execute JavaScript code within the opened WebView after it loads. This is a common requirement for mobile applications that need to:

Inject authentication tokens or user data into localStorage/sessionStorage
Customize the WebView appearance or behavior dynamically
Bridge communication between the native app and the WebView content
Implement analytics or tracking functionality

Add an executeScript method similar to other WebView implementations:

```
interface InAppBrowser {
executeScript(options: {
code: string;
callback?: (result: any) => void;
}): Promise;
}
```
Use Case Example
```
// Open WebView
await InAppBrowser.openInWebView({
url: "https://example.com/",
options: webViewOptions
});

// Inject JavaScript after page loads
await InAppBrowser.executeScript({
code: `
localStorage.setItem('authToken', 'xyz123');
localStorage.setItem('userRole', 'premium');
document.body.style.backgroundColor = '#f0f0f0';
`
});
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.