I'm trying to use the Beacon API to send some analytical data, but Chrome (68.0.3440.83) on iPhone X (iOS 11.4.1) it will not POST to a secure site (https). E.g.
iPhone Safari, iPad Chrome, Android Chrome and desktop browsers (macOS Chrome, Safari and Firefox) all work fine:
Server request:
POST / HTTP/1.1
Host: xxxx.com
Accept: */*
Accept-Language: en-gb
Accept-Encoding: gzip, deflate
Cache-Control: max-age=0
Content-Type: text/plain;charset=UTF-8
Origin: http://yyyy.com
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) CriOS/68.0.3440.83 Mobile/15G77 Safari/604.1
Connection: close
Referer: http://yyyy.com/test.html
Content-Length: 4
data
Server response:
HTTP/1.1 204 No Content
Content-Type: text/plain;charset=UTF-8
Date: Tue, 14 Aug 2018 14:15:45 GMT
Server: Apache
X-Powered-By: PHP/7.2.5
Connection: CloseAny ideas how to get Chrome working on iPhone?
--
--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss
---
You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discu...@chromium.org.
export default class HttpTracker {
constructor(config = {}) {
if (!(this instanceof HttpTracker)) return new HttpTracker(config);
if (!config.url) {
throw Error('url is required!');
}
this.config = config;
this.url = config.url;
this.first = true;
}
track(info) {
if (!this.first && navigator.sendBeacon) {
if (navigator.sendBeacon(this.url, JSON.stringify(info.value))) {
typeof info.success === 'function' && info.success(null, null);
return;
}
}
const xhr = new XMLHttpRequest();
xhr.open('POST', this.url, false);
xhr.setRequestHeader('Content-Type', 'text/plain');
xhr.withCredentials = true;
xhr.onload = info.success;
xhr.onerror = info.failure;
xhr.send(JSON.stringify(info.value));
this.first = false;
}
}