ionic-team / ionic-team/capacitor-os-inappbrowser
Feature Request: Add executeScript method for JavaScript injection
- 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
Assessment
This issue has not been assessed yet.