navigator.sendBeacon() on iPhone Chrome not posting to secure websites

989 views
Skip to first unread message

Sam Jenkins

unread,
Aug 16, 2018, 5:57:18 AM8/16/18
to Chromium-discuss

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.


navigator.sendBeacon('http://xxxx.com', 'data'); //will send a POST


navigator.sendBeacon('https://xxxx.com', 'data'); //will NOT send a POST

navigator.sendBeacon() returns true on both secure (https) and insecure (http) sites.


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: Close


Any ideas how to get Chrome working on iPhone?

PhistucK

unread,
Aug 16, 2018, 6:03:03 AM8/16/18
to sam.j...@rapidspike.com, Chromium-discuss
Can you reproduce this using Firefox, Edge or Opera on iPhone? If so, it might be an iOS issue.
If not -
You can search crbug.com for an existing issue and star it. If you cannot find one, file a new issue using the "New issue" link on the same page.
Please, do not add a "+1" or "Me too" or "Confirmed" (or similar) comment. It just wastes the time of Chrome engineers and sends unnecessary e-mails to all of the people who starred the issue.

You can reply with a link to the found or created issue and might get triaged (and fixed) faster.

Thank you.

PhistucK


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

Andreas Franzén

unread,
Aug 29, 2018, 1:18:07 AM8/29/18
to Chromium-discuss
I've been experiencing the same thing perhaps.

In my case I have a site on https://domain1.com that sends analytics data with sendBeacon to https://domain2.com. This seems to fail in a lot of cases for moblie chrome and also facebook in app browser. But it doesn't fail in all cases and so far I can only say that it seems to work if there has been a xhr request before to the same domain. So I'd be very interested if you would try that and come back with the results.

I'm thinking about trying something like this, always send the first payload with xhr after that use sendBeacon

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;
 
}
}

Andreas Franzén

unread,
Aug 29, 2018, 1:18:07 AM8/29/18
to Chromium-discuss
Made a bug report here https://bugs.chromium.org/p/chromium/issues/detail?id=878562
Let's see what they say


On Thursday, August 16, 2018 at 11:57:18 AM UTC+2, Sam Jenkins wrote:
Reply all
Reply to author
Forward
0 new messages