apache / apache/cordova-plugin-file

FileWriter silently fails in IFrame with 'Invalid Parameter type'

Open
#423 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
744
Forks
754
Avg merge
3d 4h
Merged PRs (30d)
1

Description

# Bug Report:

## FileWriter silently fails in IFrame with 'Invalid Parameter type'

## Problem

A blob/pdf is written to a temporary file on the device and then opened via the platform's OS. This workes fine when the test-doc is properly compiled into its own platform app on Android or iOS.

But I want my app to come empty and be installed without it's content document, which should be downloaded and locally stored by the final user only.

When the test-doc is downloaded by a loader-app, then written to the device storage and displayed from there in an IFrame, everything looks and works fine, except this:

* When the doc's JS creates a FileWriter, all looks good, but no data gets written. No Error occurs and the empty file is passed on to the file-opener2 and finally the PDF-viewer complains about the corrupt pdf.

On iOS the console shows an error inside the FileWriter object, on Android, no errors are reported at all.

### What is expected to happen?

- [LoaderApp](https://github.com/wehe64/cordova-LoaderApp) started, then loades & stores the [loaderDoc](https://github.com/wehe64/cordova-loaderDoc) web-document,
- the loaderDoc should be able to download, store, open and display a test-PDF from Github.

### What does actually happen?

- pdf file size always empty (or just 2bytes)
- no errors in console on Android
- on iOS in console:

``FileWriter`` error: ``'Invalid Parameter type'``

![remote console](https://github.com/wehe64/cordova-loaderDoc/raw/master/remote-console.png)

## Information

the cordova [loaderDoc](https://github.com/wehe64/cordova-loaderDoc) project
- can either run as is (w/o the LoaderApp) - and works fine
- or be payload for the LoaderApp, that is:
- have its www-folder downloaded as zip,
- be stored locally on the device
- and then opened from there in an IFrame
* **in both cases the same code runs -

in the latter case it fails**

### DROP-IN www/cordova.js:

`www/cordova.js` of the [payload document](https://github.com/wehe64/cordova-loaderDoc) is meant to be replaced during cordova's build procress.

In two cases it won't be replaced and is used as is:
- before the raw web-doc is put inside a cordova project's www/ folder (happens on the CMS creating the doc)
- if it resides in the LoaderApp's IFrame, in this case proxies of the plugins are created inside the IFrame

### Command or Code

1. build the [loaderDoc](https://github.com/wehe64/cordova-loaderDoc) as a cordova app, install/run it,

see if it manages to download, write and open the test-pdf
2. build and run the [LoaderApp](https://github.com/wehe64/cordova-LoaderApp), have it download the loaderDoc, save and open it, and finally have the loaderDoc fail its test-operation.

### Environment, Platform, Device

Desktop Linux:
```
5.8.6-1-MANJARO, x86_64 GNU/Linux
```

Desktop OS/X:
```
Systemversion: macOS 10.15.6 (19G2021)
Kernel-Version: Darwin 19.6.0
```

Android:
```sh
Galaxy Tab-A Model SM-T510
Android-Version: 10
Kernel-Version: 4.4.177-19000394
# 1 Tue June 30 16:25:20 KST 2020
```

iOS:
```sh
iPAD Air 2
iOS-Version 14.0
ModelNo MGHY2FD/A
```

### Version information

for both LoaderApp and and the loaderDoc:

```
> cordova --version
10.0.0
```
```
> cordova platform ls
Installed platforms:
android 9.0.0
ios 6.1.1
```

```sh
> cordova plugin ls
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-dialogs 2.0.2 "Notification"
cordova-plugin-file-opener2 3.0.5 "File Opener2"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-whitelist 1.3.4 "Whitelist"
```

```
- jQuery 3.5.1.min.js
- jszip.min.js
```

```sh
Android Studio 4.0.1
Build #AI-193.6911.18.40.6626763, built on June 25, 2020
Runtime version: 1.8.0_242-release-1644-b3-6222593 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 5.8.6-1-MANJARO
GC: ParNew, ConcurrentMarkSweep
Memory: 1981M
Cores: 8
Registry: ide.new.welcome.screen.force=true
Non-Bundled Plugins: org.jetbrains.kotlin, com.google.services.firebase
```

## 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

Reproduce the two flows described for LoaderApp and loaderDoc, comparing the standalone Cordova app with the downloaded document opened in an IFrame. Start with www/cordova.js and the FileWriter path in cordova-plugin-file, then verify that the stored PDF is non-empty and opens correctly on Android and iOS, with the failure no longer remaining silent.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.