GithubHelp home page GithubHelp logo

raphcal / cordova-plugin-cors Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 7.0 163 KB

Cordova plugin to allow cross origin requests (CORS) with WKWebView on iOS.

License: GNU Lesser General Public License v3.0

Objective-C 95.38% TypeScript 4.19% C 0.43%
objective-c typescript cordova-plugin cordova-ios-plugin

cordova-plugin-cors's Introduction

cordova-plugin-cors

Allow cross origin request (CORS) with WKWebView on iOS.

This plugin should be compatible with every plugin providing a WKWebView engine for Cordova and has been tested with cordova-plugin-wkwebview-engine and cordova-plugin-ionic-webview.

Installation

cordova plugin add cordova-plugin-cors

Usage

This plugin replaces the XMLHttpRequest object. There is no code modification required. It should work seamlessly.

It has been tested with pure Javascript code and with Angular HttpClient object.

Zone.js support is also integrated. Event listeners will be called within the zone used when calling send().

Example

var request = new XMLHttpRequest();
request.open('GET', 'https://cordova.apache.org', true);

request.onreadystatechange = function(event) {
    if (this.readyState === XMLHttpRequest.DONE) {
        if (this.status === 200) {
            console.info('Cross origin request was sent with success!', this.responseText);
        } else {
            console.error('Cross origin request failed :(', this.status, this.statusText);
        }
    }
};

request.send(null);

Limitations

Synchronous requests are not supported.

cordova-plugin-cors's People

Contributors

jdkcn avatar raphcal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cordova-plugin-cors's Issues

ReferenceError: Can't find variable: Zone

Hi!
I am using a plugin and getting an error in ios Safari.
I do not use zone.js

this.zone = Zone ? Zone.current : undefined; // ReferenceError: Can't find variable: Zone

App crashing when HTTP call has **accept=application/pdf**

I am using this Cordova plugin in my Cordova application. This plugin saved me a lot of my time. It worked for all my cases except the 1 following case.

Whem I am making API with https://vsltst1.applaudsolutions.com/OA_HTML/applaud/api/assignments/259/oracle-payslips/US/8809896?_accept=application/pdf&inline=true&biPublisherTemplate=# app got broken. After I debug got to know it's because of accept query parameter.

If I change from application/pdf to application/json it's working. seems like Mime-types not handled properly. @Raphcal Could you please help with this?

FormData not working

image

image

image

value instanceof File to check file type not working

the fileReader.addEventListener is undefined.

File upload crash

Ajax upload with FormData not working.

uploadFile(opts) {
    const { file } = opts;
    const formData = new FormData();

    function getBlobBydataURI(dataURI, type) {
      var binary = atob(dataURI);
      var array = [];
      for (var i = 0; i < binary.length; i++) {
        array.push(binary.charCodeAt(i));
      }
      return new Blob([new Uint8Array(array)], { type: type });
    }
    const $Blob = getBlobBydataURI(file, 'image/jpeg');
    formData.append('file', $Blob, 'file_' + Date.parse(new Date()) + '.jpeg');
    return apiFormSubmit({ url: '/upload', data: formData })
  }

error on:

    if (![data isEqual:[NSNull null]]) {
        [request setHTTPBody:[data dataUsingEncoding:NSUTF8StringEncoding]];
    }

cordova ios 6.1.0 wkwebview all xhr POST requests failing and are converting as blob request.

Hi,

I have migrated the Cordova app from UIWebview to WKWebview.I have a native scanner screen that is invoked from the webpage and to invoke this I am using the "cordova-plugin-cors".
Which is working fine by launching a scanner. But on the same page, the other ajax post calls are getting failed and they are converted as blob requests, along with that it gives certificate trust error logs.

I tried removing the "cordova-plugin-cors" plugin post that all the post ajax call works perfectly. But Scanner will not be invoked without xhr plugin.

All the calls are getting invoked using the xhr.js file where the post calls are failing.
Can someone please help me to fix this issue?

XHR plugin issue

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.