You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by GitBox <gi...@apache.org> on 2021/01/28 14:54:00 UTC

[GitHub] [cordova-plugin-file] JoCa96 opened a new issue #453: cordova-plugin-file overwrites the global File variable on iOS

JoCa96 opened a new issue #453:
URL: https://github.com/apache/cordova-plugin-file/issues/453


   # Bug Report
   Hi, we had this plugin in our Capacitor project as a dependency of `cordova-plugin-advanced-http`.
   
   It is not possible to use the [Browsers File API](https://developer.mozilla.org/en-US/docs/Web/API/File/File) with this plugin in Capacitor on iOS.
   
   The following snippet will not work correctly:
   ```javascript
   var file = new File(["foo"], "foo.txt", {
     type: "text/plain",
   });
   ```
   
   ## Problem
   The `cordova-plugin-file` is overwriting the global/globalThis/window File variable.
   
   I never actively used this Plugin, but skimmed through the docs and it doesn't seem like this behaviour is intended.
   
   ### What is expected to happen?
   I expect to be able to use the Browsers `File` API as described by [MDN](https://developer.mozilla.org/en-US/docs/Web/API/File/File) to create a File instance.
   
   
   ### What does actually happen?
   An incorrect File instance is created, which can not be used as describe by [MDN](https://developer.mozilla.org/en-US/docs/Web/API/File/File) to create a File instance.
   
   
   ## Information
   
   We are only building an iOS App, so I can only confirm this bug for iOS.
   
   ### Command or Code
   Create an Capacitor iOS project and install the `cordova-plugin-file` package.
   
   Build the iOS app and use XCode to build and run the App on an iPhone/iPad connected via USB.
   Use Safari DevTools to debug the Capacitor App and run the following snippet.
   Inspect the `file` variable or inspect the `File` protoype's constructor and you will notice that it is not the Browsers native `File` API.
   
   ```javascript
   var file = new File(["foo"], "foo.txt", {
     type: "text/plain",
   });
   ```
   
   ### Environment, Platform, Device
   * Capacitor 2.4.6
   * iOS 14.3
   * iPhone 8
   
   
   
   ### Version information
   ```json
       "@capacitor/cli": "2.4.6",
       "@capacitor/core": "2.4.6",
       "@capacitor/ios": "^2.4.6",
       "ionic": "^5.4.14",
       "@ionic/angular": "^5.4.1",
       "@ionic/angular-toolkit": "~2.0.0",
       "ionic-native": "^2.9.0",
       "@ionic-native/file-transfer": "^5.29.0",
       "cordova-plugin-file": "^6.0.2",
       "cordova-plugin-advanced-http": "^2.2.0",
   ```
   
   ## Checklist
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [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


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] Tukkan edited a comment on issue #453: cordova-plugin-file overwrites the global File variable on iOS

Posted by GitBox <gi...@apache.org>.
Tukkan edited a comment on issue #453:
URL: https://github.com/apache/cordova-plugin-file/issues/453#issuecomment-863544803


   Hehe, I spent like 4 hours figuring out why my Files are wrongly created until I found out that the API has been replaced.
   
   The dirty hack would be to put 
   
   ```
     <script>
       window.NativeFile = File;
     </script>
   ```
     
     in index.html header so that we could still have the reference to old File API.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] breautek commented on issue #453: cordova-plugin-file overwrites the global File variable on iOS

Posted by GitBox <gi...@apache.org>.
breautek commented on issue #453:
URL: https://github.com/apache/cordova-plugin-file/issues/453#issuecomment-769151280


   > I never actively used this Plugin, but skimmed through the docs and it doesn't seem like this behaviour is intended.
   
   This plugin has its own `File` class, which is in no way related to the browser's native `File` class. This is intentional... but it was decision from way back in the day when browsers didn't really had a usable `File` class (outside of the readonly `File` instance obtained when using the `<input type="file">` field)
   
   Personally, I do agree, the plugin should avoid clobbering features provided by the browser. But changing this would probably require a discussion on the [mailing list](https://cordova.apache.org/contact/) as this plugin is a dependency of several other plugins. I suppose the simplest change (and simplest migration) would just change the clobber space to `cordova.file` or something.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] breautek commented on issue #453: cordova-plugin-file overwrites the global File variable on iOS

Posted by GitBox <gi...@apache.org>.
breautek commented on issue #453:
URL: https://github.com/apache/cordova-plugin-file/issues/453#issuecomment-771689178


   > @breautek how do I update the clobber space to using the explicit namespace cordova.file as I'm having this same problem. That, or is it possible to create a File Reference using the cordova plugin that will be able to be Read in my API?
   
   The only way to do this is to fork the plugin and change the `plugin.xml`:
   
   https://github.com/apache/cordova-plugin-file/blob/a4a7bfe2aa48f5c44eb8af264c1c6540ea4dd072/plugin.xml#L48-L50
   
   Doing so may break things that depend on this plugin however, and may require other changes within the plugin's JS sources itself.
   
   A safer workaround might be to capture a reference to the original `File` object. Do this before you load the `cordova.js` file.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] Go4th commented on issue #453: cordova-plugin-file overwrites the global File variable on iOS

Posted by GitBox <gi...@apache.org>.
Go4th commented on issue #453:
URL: https://github.com/apache/cordova-plugin-file/issues/453#issuecomment-771685607






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] breautek commented on issue #453: cordova-plugin-file overwrites the global File variable on iOS

Posted by GitBox <gi...@apache.org>.
breautek commented on issue #453:
URL: https://github.com/apache/cordova-plugin-file/issues/453#issuecomment-771689178


   > @breautek how do I update the clobber space to using the explicit namespace cordova.file as I'm having this same problem. That, or is it possible to create a File Reference using the cordova plugin that will be able to be Read in my API?
   
   The only way to do this is to fork the plugin and change the `plugin.xml`:
   
   https://github.com/apache/cordova-plugin-file/blob/a4a7bfe2aa48f5c44eb8af264c1c6540ea4dd072/plugin.xml#L48-L50
   
   Doing so may break things that depend on this plugin however, and may require other changes within the plugin's JS sources itself.
   
   A safer workaround might be to capture a reference to the original `File` object. Do this before you load the `cordova.js` file.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] dominic-simplan commented on issue #453: cordova-plugin-file overwrites the global File variable on iOS

Posted by GitBox <gi...@apache.org>.
dominic-simplan commented on issue #453:
URL: https://github.com/apache/cordova-plugin-file/issues/453#issuecomment-879199085


   Probably duplicate of #316.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] Tukkan commented on issue #453: cordova-plugin-file overwrites the global File variable on iOS

Posted by GitBox <gi...@apache.org>.
Tukkan commented on issue #453:
URL: https://github.com/apache/cordova-plugin-file/issues/453#issuecomment-863544803


   Hehe, I spent like 4 hours figuring out why my Files are wrongly loaded until I found out that the API has been replaced.
   
   The dirty hack would be to put 
   
   ```
     <script>
       window.NativeFile = File;
     </script>
   ```
     
     in index.html header so that we could still have the reference to old File API.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] Go4th commented on issue #453: cordova-plugin-file overwrites the global File variable on iOS

Posted by GitBox <gi...@apache.org>.
Go4th commented on issue #453:
URL: https://github.com/apache/cordova-plugin-file/issues/453#issuecomment-771719010


   @breautek Thanks man. 
   Appears that the File Plugin reference is global beyond the component/utility in which it's used due to being imported into the AppModule, but updating the clobber did work. Thanks for the tip. Hopefully cordova will update this namespace collision in a later version as using the browser's File() method is very useful in modern development.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] Go4th commented on issue #453: cordova-plugin-file overwrites the global File variable on iOS

Posted by GitBox <gi...@apache.org>.
Go4th commented on issue #453:
URL: https://github.com/apache/cordova-plugin-file/issues/453#issuecomment-771685607


   @breautek  how do I update the clobber space to using the explicit namespace cordova.file as I'm having this same problem. That, or is it possible to create a File Reference using the cordova plugin that will be able to be Read in my API?
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] Go4th commented on issue #453: cordova-plugin-file overwrites the global File variable on iOS

Posted by GitBox <gi...@apache.org>.
Go4th commented on issue #453:
URL: https://github.com/apache/cordova-plugin-file/issues/453#issuecomment-771686501


   @JoCa96 where you able to resolve this issue? How?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] Tukkan removed a comment on issue #453: cordova-plugin-file overwrites the global File variable on iOS

Posted by GitBox <gi...@apache.org>.
Tukkan removed a comment on issue #453:
URL: https://github.com/apache/cordova-plugin-file/issues/453#issuecomment-863544803


   Hehe, I spent like 4 hours figuring out why my Files are wrongly created until I found out that the API has been replaced.
   
   The dirty hack would be to put 
   
   ```
     <script>
       window.NativeFile = File;
     </script>
   ```
     
     in index.html header so that we could still have the reference to old File API.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] JoCa96 commented on issue #453: cordova-plugin-file overwrites the global File variable on iOS

Posted by GitBox <gi...@apache.org>.
JoCa96 commented on issue #453:
URL: https://github.com/apache/cordova-plugin-file/issues/453#issuecomment-827353696


   @Go4th Sorry, I missed the notification for your comment. We were just able to remove the `cordova-plugin-advanced-http` plugin, because we didn't actively use it. Not really a fix, sorry.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org