Closed enricodeleo closed 3 years ago
I tried hardcoding cors-anywhere proxy and now the update.zip is downloaded (I cannot understand why it incurs in cors limitation in the first place, but as a temporary fix the proxy works).
After the download, however, the plugin unzips the file creating an unzipped
directory which is empty.
Error is:
promiseReactionJob@[native code]
⚡️ [error] - [CodePush] An error occurred during sync. Could not unzip packageFailed to unzip.
Any ideas?
Nonetheless it cannot download the file, apparently due to cors restrictions. It does create the destination folder but nothing more.
The CORS appears to be coming from the way the JS is doing the request. I was able to get the download happening by adding the following to my index.html
's <head>
<meta
http-equiv="Content-Security-Policy"
content="default-src * 'unsafe-inline' 'unsafe-eval'; script-src * 'unsafe-inline' 'unsafe-eval'; connect-src * data: blob: 'unsafe-inline' 'unsafe-eval'; img-src * data: blob: 'unsafe-inline'; frame-src *; style-src * 'unsafe-inline';"
/>
Note this is very insecure. It kinda works for now, but a proper review is on my todo list.
@gnunicorn I tried the same but got errors on other parts of the app (don't know why). Furthermore, since @capacitor-community/http
is installed I supposed it would have bypassed CORS limits.
As I said I solved with a cors proxy for the moment, but still cannot find why it fails unzipping the package. I downloaded manually the same url returned by the plugin and it is a zip file, with the correct content.
@leo6104 any suggestion? Is there something I'm missing?
I found the problem in yesterday and the root cause came from @capacitor-community/http plugin and @capacitor/core >=3.0.0-beta.2
After @capacitor/core 3.0.0-beta.2 version, registerWebPlugin
function is fully deprecated.
According to the implementation (https://github.com/capacitor-community/http/blob/master/src/web.ts) It export web plugin object to 'Http' variable.
const Http = new HttpPluginWeb();
export { Http };
registerWebPlugin(Http);
So, in mapiacompany/capacitor-codepush
plugin code (https://github.com/mapiacompany/capacitor-codepush/blob/capacitor/src/remotePackage.ts#L9)
import { Http } from '@capacitor-community/http';
...
await Http.downloadFile(...);
It will use XMLHttpRequest to download file and it cause CORS issue.
To solve this problem, it should be change in @capacitor-community/http plugin to use registerPlugin
function like this.
const Http = registerPlugin<HttpPlugin>('Http', { web: new HttpPluginWeb() });
export { Http };
They already change the deprecated usage and release 1.0.0-alpha.0 to support Capacitor 3.
Please install @capacitor-community/http 1.0.0-alpha.0 version and try again :) If it work as native plugin, we don't need to add meta tag in head tag.
Thanks @leo6104. I installed @capacitor-community/http@next
and no more CORS complaints are found.
However, it still fails with new errors.
This is the log (.sync() runs on start, after the Vue app is mounted):
Loading app at capacitor://localhost...
2021-02-26 19:47:27.300017+0100 App[29727:510456] WF: === Starting WebFilter logging for process App
2021-02-26 19:47:27.300230+0100 App[29727:510456] WF: _userSettingsForUser : (null)
2021-02-26 19:47:27.300374+0100 App[29727:510456] WF: _WebFilterIsActive returning: NO
⚡️ [warn] - Capacitor WebPlugin "FirebaseAnalytics" config object was deprecated in v3 and will be removed in v4.
⚡️ [warn] - Capacitor plugin "FirebaseAnalytics" is using the deprecated "registerWebPlugin()" function
⚡️ To Native -> CodePush notifyApplicationReady 40092063
⚡️ To Native -> CodePush getDeploymentKey 40092064
⚡️ TO JS undefined
⚡️ TO JS {"value":"0Ns-oFEhe_FF8SBMXxfARPs22oZLOPx9qm5pS"}
⚡️ To Native -> CodePush getServerURL 40092065
⚡️ TO JS {"value":"https:\/\/codepush.appcenter.ms\/"}
⚡️ To Native -> CodePush getAppVersion 40092066
⚡️ TO JS {"value":"1.0.2"}
⚡️ To Native -> CodePush getDeploymentKey 40092067
⚡️ TO JS {"value":"0Ns-oFEhe_FF8SBMXxfARPs22oZLOPx9qm5pS"}
⚡️ WebView loaded
⚡️ To Native -> Device getInfo 40092068
⚡️ TO JS {"uuid":"94962020-3828-4F45-A480-819E0D7097EA","webViewVersion":"14.4","isVirtual":true,"operatingSystem":"ios","model":"iPhone","osVersion":"14.4","name":"iPhone 11 Pro","diskFree":312747782144,"memUsed":138620928,"diskTotal":499898105856,"platform":"ios"
⚡️ To Native -> Filesystem readFile 40092069
ERROR MESSAGE: {"message":"The file “currentPackage.json” couldn’t be opened because there is no such file.","errorMessage":"The file “currentPackage.json” couldn’t be opened because there is no such file."}
⚡️ [error] - {"message":"The file “currentPackage.json” couldn’t be opened because there is no such file.","errorMessage":"The file “currentPackage.json” couldn’t be opened because there is no such file."}
⚡️ To Native -> CodePush getAppVersion 40092070
⚡️ TO JS {"value":"1.0.2"}
⚡️ To Native -> CodePush getBinaryHash 40092071
ERROR MESSAGE: {"message":"An error occurred when trying to get the hash of the binary contents. ","errorMessage":"An error occurred when trying to get the hash of the binary contents. "}
⚡️ [error] - {"message":"An error occurred when trying to get the hash of the binary contents. ","errorMessage":"An error occurred when trying to get the hash of the binary contents. "}
⚡️ [error] - [CodePush] Could not get binary hash.Error: Could not get binary hash.
⚡️ To Native -> CodePush getAppVersion 40092072
⚡️ TO JS {"value":"1.0.2"}
⚡️ [log] - [CodePush] Checking for update.
⚡️ To Native -> Http request 40092073
2021-02-26 19:47:28.148231+0100 App[29727:510858] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed
2021-02-26 19:47:28.477430+0100 App[29727:510864] 7.6.0 - [Firebase/Analytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement
2021-02-26 19:47:28.495653+0100 App[29727:511028] 7.6.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled
2021-02-26 19:47:28.496266+0100 App[29727:511028] 7.6.0 - [Firebase/Analytics][I-ACS023220] Analytics screen reporting is enabled. Call +[FIRAnalytics logEventWithName:FIREventScreenView parameters:] to log a screen view event. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO (boolean) in the Info.plist
⚡️ TO JS {"data":{"update_info":{"is_mandatory":true,"package_size":7686705,"target_binary_range":"1.0.2","is_available":true,"label":"v3","package_hash":"294bf1bd13749e1d337f2b466d5d26e417aa60d86165331e631cd0b9296da1be","description":"Modified featured bg color","
⚡️ To Native -> CodePush isFailedUpdate 40092074
⚡️ TO JS {"value":0}
⚡️ [log] - [CodePush] An update is available. {"isDownloading":false,"appVersion":"1.0.2","deploymentKey":"OMISSSIS","description":"Modified featured bg color","downloadUrl":"https://codepushupdates.azureedge.net/storagev2/mA8sN8fFC8uwhynb0grC52Guiqz737b0c97e-9014-45d0-ac70-2808d4b64745","isMandatory":true,"label":"v3","packageHash":"294bf1bd13749e1d337f2b466d5d26e417aa60d86165331e631cd0b9296da1be","packageSize":7686705,"failedInstall":0}
⚡️ [log] - [CodePush] Downloading update
⚡️ To Native -> Filesystem getUri 40092075
⚡️ TO JS {"uri":"file:\/\/\/Users\/enricodeleo\/Library\/Developer\/CoreSimulator\/Devices\/5A837092-6BE7-4D47-B5CE-EDEB98DE7DF5\/data\/Containers\/Data\/Application\/DAC09C3F-C133-40DF-B69F-B98E018FF367\/Documents\/codepush\/download\/update.zip"}
⚡️ To Native -> Filesystem stat 40092076
ERROR MESSAGE: {"message":"The file “download” couldn’t be opened because there is no such file.","errorMessage":"The file “download” couldn’t be opened because there is no such file."}
⚡️ [error] - {"message":"The file “download” couldn’t be opened because there is no such file.","errorMessage":"The file “download” couldn’t be opened because there is no such file."}
⚡️ To Native -> Filesystem mkdir 40092077
⚡️ TO JS undefined
⚡️ To Native -> Filesystem stat 40092078
ERROR MESSAGE: {"message":"The file “update.zip” couldn’t be opened because there is no such file.","errorMessage":"The file “update.zip” couldn’t be opened because there is no such file."}
⚡️ [error] - {"message":"The file “update.zip” couldn’t be opened because there is no such file.","errorMessage":"The file “update.zip” couldn’t be opened because there is no such file."}
⚡️ To Native -> Http downloadFile 40092079
⚡️ TO JS {"url":"https:\/\/codepushupdates.azureedge.net\/storagev2\/mA8sN8fFC8uwhynb0grC52Guiqz737b0c97e-9014-45d0-ac70-2808d4b64745","status":200,"headers":{"x-ms-lease-status":"unlocked","x-ms-request-id":"6e177336-201e-0059-6c6f-0c9829000000","Date":"Fri, 26 Fe
⚡️ To Native -> CodePush isFailedUpdate 40092080
⚡️ TO JS {"value":0}
⚡️ [log] - [CodePush] Package download success: {"deploymentKey":"OMISSSIS","description":"Modified featured bg color","label":"v3","appVersion":"1.0.2","isMandatory":true,"packageHash":"294bf1bd13749e1d337f2b466d5d26e417aa60d86165331e631cd0b9296da1be","isFirstRun":false,"failedInstall":0,"localPath":"file:///Users/enricodeleo/Library/Developer/CoreSimulator/Devices/5A837092-6BE7-4D47-B5CE-EDEB98DE7DF5/data/Containers/Data/Application/DAC09C3F-C133-40DF-B69F-B98E018FF367/Documents/codepush/download/update.zip"}
⚡️ [log] - [CodePush] Installing update
⚡️ To Native -> Filesystem stat 40092081
⚡️ To Native -> Http request 40092082
ERROR MESSAGE: {"errorMessage":"The file “unzipped” couldn’t be opened because there is no such file.","message":"The file “unzipped” couldn’t be opened because there is no such file."}
⚡️ To Native -> Filesystem mkdir 40092083
⚡️ [error] - {"errorMessage":"The file “unzipped” couldn’t be opened because there is no such file.","message":"The file “unzipped” couldn’t be opened because there is no such file."}2021-02-26 19:47:37.223651+0100 App[29727:510857] GET method must not have a body
⚡️ TO JS undefined
⚡️ To Native -> Filesystem getUri 40092084
⚡️ TO JS {"uri":"file:\/\/\/Users\/enricodeleo\/Library\/Developer\/CoreSimulator\/Devices\/5A837092-6BE7-4D47-B5CE-EDEB98DE7DF5\/data\/Containers\/Data\/Application\/DAC09C3F-C133-40DF-B69F-B98E018FF367\/Documents\/codepush\/download\/unzipped\/"}
2021-02-26 19:47:37.228128+0100 App[29727:510857] Task <D520DF48-8714-48E3-99BA-958E2544D30A>.<3> finished with error [-1103] Error Domain=NSURLErrorDomain Code=-1103 "resource exceeds maximum size" UserInfo={NSLocalizedDescription=resource exceeds maximum size, NSErrorFailingURLStringKey=https://codepush.appcenter.ms/v0.1/public/codepush/report_status/download, NSErrorFailingURLKey=https://codepush.appcenter.ms/v0.1/public/codepush/report_status/download, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <D520DF48-8714-48E3-99BA-958E2544D30A>.<3>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <D520DF48-8714-48E3-99BA-958E2544D30A>.<3>, NSUnderlyingError=0x600002d15560 {Error Domain=kCFErrorDomainCFNetwork Code=-1103 "(null)"}}
ERROR MESSAGE: {"code":"REQUEST","errorMessage":"Error","message":"Error"}
⚡️ To Native -> CodePush unzip 40092085
⚡️ [error] - {"code":"REQUEST","errorMessage":"Error","message":"Error"}
ERROR MESSAGE: {"errorMessage":"Failed to unzip","message":"Failed to unzip"}
⚡️ [error] - {"errorMessage":"Failed to unzip","message":"Failed to unzip"}
⚡️ [error] - [CodePush] Could not unzip packageFailed to unzip. StackTrace: capacitor://localhost/js/chunk-vendors.67bc88d6.js:1:14868
generatorResume@[native code]
c@capacitor://localhost/js/chunk-vendors.67bc88d6.js:1:14200
promiseReactionJob@[native code]
⚡️ [error] - [CodePush] An error occurred during sync. Could not unzip packageFailed to unzip. StackTrace: capacitor://localhost/js/chunk-vendors.67bc88d6.js:1:14868
generatorResume@[native code]
c@capacitor://localhost/js/chunk-vendors.67bc88d6.js:1:14200
promiseReactionJob@[native code]
⚡️ To Native -> Http request 40092086
2021-02-26 19:47:37.233431+0100 App[29727:510857] GET method must not have a body
2021-02-26 19:47:37.233761+0100 App[29727:510857] Task <4E82323C-77C0-4DE0-A93C-0D3D658A7D33>.<4> finished with error [-1103] Error Domain=NSURLErrorDomain Code=-1103 "resource exceeds maximum size" UserInfo={NSLocalizedDescription=resource exceeds maximum size, NSErrorFailingURLStringKey=https://codepush.appcenter.ms/v0.1/public/codepush/report_status/deploy, NSErrorFailingURLKey=https://codepush.appcenter.ms/v0.1/public/codepush/report_status/deploy, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <4E82323C-77C0-4DE0-A93C-0D3D658A7D33>.<4>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <4E82323C-77C0-4DE0-A93C-0D3D658A7D33>.<4>, NSUnderlyingError=0x600002d151d0 {Error Domain=kCFErrorDomainCFNetwork Code=-1103 "(null)"}}
ERROR MESSAGE: {"errorMessage":"Error","message":"Error","code":"REQUEST"}
⚡️ [error] - {"errorMessage":"Error","message":"Error","code":"REQUEST"}
I do not understand where the error comes from
@enricodeleo I think it has a problem with @capacitor-community/http 1.0.0-alpha.0 Http.downloadFile
.
In 1.0.0-alpha.0 of @capacitor-community/http doesn't implement downloadFile correctly.
Current implementation
@objc func downloadFile(_ call: CAPPluginCall) {
// Protect against bad values from JS before calling request
guard let u = call.getString("url") else { return call.reject("Must provide a URL") }
guard let _ = call.getString("filePath") else { return call.reject("Must provide a file path to download the file to") }
guard let _ = URL(string: u) else { return call.reject("Invalid URL") }
do {
try HttpRequestHandler.request(call)
} catch let e {
call.reject(e.localizedDescription)
}
}
It just do http request and nothing to save response into file.
master branch implementation https://github.com/capacitor-community/http/blob/master/ios/Plugin/Plugin.swift#L36
We should wait for next release (https://github.com/capacitor-community/http/pull/73)
Now i cannot wait for next release in my service. So i create fork repository and bundling the dist folder.
Please use below command until next release of @capacitor-community/http
npm i https://github.com/leo6104/capacitor-community-http.git#dist -D
npx cap sync
Thank you!
Unfortunately I have the same error above even after
npm i https://github.com/leo6104/capacitor-community-http.git#dist -D
npx cap sync
Should I uninstall @capacitor-community/http
before trying?
I am also getting this issue, even after installing your fork:
[CodePush] An error occurred during sync. Could not unzip packageFailed to unzip. StackTrace: ionic://localhost/main-es2015.bd46a7fc28e4051f2aca.js:1:879506
generatorResume@[native code]
However, interestingly, it seems the file downloads successfully:
[CodePush] Package download success: {"deploymentKey":"XXXXXXXXXXXXXXXXXXXXXXXXX","label":"v2","appVersion":"10.0.3","isMandatory":false,"packageHash":"XXXXXXXXXXXXXXXXXX","isFirstRun":false,"failedInstall":0,"localPath":"file:///var/mobile/Containers/Data/Application/XXXXXXXXXX/Documents/codepush/download/update.zip"}
Correction, the file is downloaded but NOT saved. Just like you said. Looks like the native code is still not implemented in your fork... here it is:
You can use my dist fork for now: package.json:
"@capacitor-community/http": "github:lincolnthree/capacitor-community-http#dist",
I have opened a ticket for this: https://github.com/capacitor-community/http/issues/104
@lincolnthree They already implement download function in HttpRequestHandler.download (https://github.com/capacitor-community/http/blob/capacitor-v3/ios/Plugin/HttpRequestHandler.swift)
but in the Plugin.swift code, they didn't call download function. just call request (now)
try HttpRequestHandler.request(call)
I think we can fix this issue with just replace request
to download
in capacitor-v3
branch.
// Protect against bad values from JS before calling request
guard let u = call.getString("url") else { return call.reject("Must provide a URL") }
guard let _ = call.getString("filePath") else { return call.reject("Must provide a file path to download the file to") }
guard let _ = URL(string: u) else { return call.reject("Invalid URL") }
do {
try HttpRequestHandler.download(call) <--- HERE!
} catch let e {
call.reject(e.localizedDescription)
}
ps) I add https://github.com/leo6104/capacitor-community-http/commit/556fe433a52d8146f88c7c042f070069a94b129d commit .
npm i https://github.com/leo6104/capacitor-community-http.git#dist -D
will use HttpRequestHandler.download
@leo6104 Does this work for you? It doesn't for me.
Still error :(
[error] - [CodePush] An error occurred during sync. Could not unzip packageFailed to unzip. StackTrace: capacitor://localhost/js/chunk-vendors.19010d58.js:1:14868
generatorResume@[native code]
s@capacitor://localhost/js/chunk-vendors.19010d58.js:1:14200
promiseReactionJob@[native code]
⚡️ To Native -> Http request 25977972
2021-03-04 23:37:01.127554+0100 App[4869:100573] GET method must not have a body
2021-03-04 23:37:01.127919+0100 App[4869:100573] Task <43D57CB9-E61D-401A-9B23-E626E6A0D7B8>.<4> finished with error [-1103] Error Domain=NSURLErrorDomain Code=-1103 "resource exceeds maximum size" UserInfo={NSLocalizedDescription=resource exceeds maximum size, NSErrorFailingURLStringKey=https://codepush.appcenter.ms/v0.1/public/codepush/report_status/deploy,
Update @capacitor-community/http to 1.0.0-alpha.1. and follow below instruction
Tried that very same sequence of actions but now I get
ERROR Failed to compile with 1 error 7:44:38 PM
This dependency was not found:
* @capacitor-community/http in ./node_modules/capacitor-codepush/dist/esm/remotePackage.js
To install it, you can run: npm install --save @capacitor-community/http
ERROR Build failed with errors.
npm ERR! code 1
npm ERR! path /Users/enricodeleo/Development/moovenda/app
npm ERR! command failed
npm ERR! command sh -c vue-cli-service build
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/enricodeleo/.npm/_logs/2021-03-07T18_44_38_568Z-debug.log
@enricodeleo can you try this command and again?
npm install --save @capacitor-community/http@next
Thanks @leo6104 apparently we are a step ahead now!
I have this error, but maybe I misunderstood the guide.
TO JS {"value":0}
⚡️ To Native -> Filesystem copy 20210907
ERROR MESSAGE: {"errorMessage":"The file “currentPackage.json” couldn’t be opened because there is no such file.","message":"The file “currentPackage.json” couldn’t be opened because there is no such file."}
⚡️ [error] - {"errorMessage":"The file “currentPackage.json” couldn’t be opened because there is no such file.","message":"The file “currentPackage.json” couldn’t be opened because there is no such file."}
⚡️ To Native -> CodePush getNativeBuildTime 20210908
⚡️ TO JS {"value":"1615149507699"}
⚡️ To Native -> CodePush getAppVersion 20210909
⚡️ TO JS {"value":"1.0.2"}
⚡️ To Native -> Filesystem writeFile 20210910
⚡️ TO JS {"uri":"file:\/\/\/Users\/enricodeleo\/Library\/Developer\/CoreSimulator\/Devices\/5A837092-6BE7-4D47-B5CE-EDEB98DE7DF5\/data\/Containers\/Data\/Application\/1397008F-FE48-4BCE-8354-B6091BDE3D41\/Documents\/codepush\/currentPackage.json"}
⚡️ To Native -> CodePush preInstall 20210911
ERROR MESSAGE: {"errorMessage":"Could not find start page in package.","message":"Could not find start page in package."}
⚡️ [error] - {"errorMessage":"Could not find start page in package.","message":"Could not find start page in package."}
⚡️ [error] - [CodePush] Preinstall failure. Could not find start page in package.. StackTrace: d@capacitor://localhost/js/chunk-vendors.9a7347c3.js:3:2078
capacitor://localhost/js/chunk-vendors.9a7347c3.js:3:3632
⚡️ [error] - [CodePush] An error has occured while installing the package. Could not find start page in package.. StackTrace: c@capacitor://localhost/js/chunk-vendors.9a7347c3.js:1:18779
promiseReactionJob@[native code]
⚡️ [error] - [CodePush] An error occurred during sync. An error has occured while installing the package. Could not find start page in package.. StackTrace: c@capacitor://localhost/js/chunk-vendors.9a7347c3.js:1:18779
promiseReactionJob@[native code]
⚡️ To Native -> Http request 20210912
Since my app is Ionic Vue and I get a ./dist
directory on build, I push it by doing
appcenter codepush release -a Project/app-ios -c dist/ -d Production --target-binary-version "^1.0.2" -m --description "Description of this update"
Am I missing something?
@enricodeleo You need to make sure your app release bundle (appcenter codepush zip) has a www/index.html
file in the www folder. Make sure you use the appcenter codepush --update-contents-path ./www
command with a local build/dist folder that has www
as the target directory.
Otherwise codepush will not work with the error you see above.
I'd recommend inspecting the filesystem of your device/simulator to see what has actually been unzipped. That will help you know what problem you need to solve. But capacitor bundles must have a www/index.html
.
@lincolnthree it now works as expected.
For anyone using Ionic Vue, the build script typically creates a dist
directory, the only thing to do is renaming it to www and pushing with (for example)
appcenter codepush release -a Project/app-ios -c www -d Production --target-binary-version "^1.0.2" -m --description "Description of this update"
@enricodeleo Exactly! I'm glad you were able to get it working. I also had this issue because our build & release scripts create a dist/
folder. So I was stunned to see it did not work when doing a prod build, but did work using a dev build. This ended up being the same root cause.
Thanks so much for filing an issue or feature request! Please fill out the following (wherever relevant):
Description
After #8 the plugin starts and syncs with the appcenter. Nonetheless it cannot download the file, apparently due to cors restrictions. It does create the destination folder but nothing more.
I tried adding
@capacitor-community/http
but nothing changes.Any hints?