apache / apache/cordova-plugin-inappbrowser

inAppBrowser executeScript File Does Not Work with Local File

Open
#679 2 comments 2 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.1k
Forks
2.2k
PR merge metrics
No merged PRs in 30d

Description

# Bug Report

// none of these file paths work
var toInject = cordova.file.applicationDirectory + "www/js/inject.js";
//var toInject = "www/js/inject.js";
//var toInject = "js/inject.js";
//var toInject = "inject.js";

inAppBrowserRef.executeScript(
{
file: toInject
//code:
// "alert('inline injected');" // inline code works as expected
},
function () {
alert("inject finished");
}
);

## Problem

Trying to use inAppBrowser and inject JS from a file that is stored in the www folder. Doesn't work, no error messages given. Inline code injection works, but is very sloppy to use if you have any decent length of code.

Also, it does work if you include a .js file that is hosted on the internet. This seems like a very poor way of programming... You would want to have your .js file that your injecting to actually be included in the App, not imported from a website.

### What is expected to happen?

Load the JS file

### What does actually happen?

Nothing, no error.

## Information

Newest version of everything. See version section.

### Command or Code

Code posted above

### Environment, Platform, Device

Android

### Version information
cordova-clipboard 1.3.0 "Clipboard"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-inappbrowser 3.2.0 "InAppBrowser"
cordova-plugin-splashscreen 5.0.3 "Splashscreen"
cordova-plugin-whitelist 1.3.4 "Whitelist"

cordova@9.0.0 | Apache-2.0 | deps: 8 | versions: 1201

bin: cordova

dist
.tarball: https://registry.npmjs.org/cordova/-/cordova-9.0.0.tgz

dependencies:
configstore: ^4.0.0 cordova-lib: ^9.0.0 insight: ^0.10.1 nopt: ^4.0.1
cordova-common: ^3.1.0 editor: ^1.0.0 loud-rejection: ^2.0.0 update-notifier: ^2.5.0

dist-tags:
3.6.0-0.2.8: 3.6.0-0.2.8 nightly: 10.0.0-nightly.2020.4.20.093c53cc
latest: 9.0.0 rc: 5.3.3

## Checklist

- [x ] I searched for existing GitHub issues
- [x ] I updated all Cordova tooling to most recent version
- [ x] I included all the necessary information above

Contributor guide

Open the contributing guide

Research direction

Start at the Android implementation of the executeScript({file: ...}) entry point and reproduce the issue with the local www/js/inject.js paths shown in the report. Compare the failing local-file behavior with the working inline-code and remote-file cases; done means a bundled JavaScript file loads and executes without requiring an external website.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java, javascript
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.