question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

document.cookie non functional in ios 6.0.0/6.1.0

See original GitHub issue

Bug Report

Using

<preference name="scheme" value="app" />
<preference name="hostname" value="localhost" />

renders document.cookie completely non-functional.

What is expected to happen?

To see this just do

cordova create myApp org.apache.cordova.myApp myApp
cd myApp
(add scheme and hostname preferences to config.xml)
cordova platform add ios@^6.1.0

Now load myApp into the emulator from xcode, then go to the Safari web inspector and try

document.cookie="foo=bar"
document.cookie

Result is empty string.

Removing the scheme and hostname preferences enables document.cookie, but then you don’t have the benefit of the scheme.

With ios 5 I used cordova-plugin-wkwebview-file-xhr to enable loading both local and remote urls, and cordova-plugin-wkwebviewxhrfix to enable Javascript trap information to be passed to my code.

With ios 6.1.0 I am still using cordova-plugin-wkwebview-file-xhr (I just removed the dependency on the wkwebview plugin) and this removes the need for the scheme and hostname preferences. However, the scheme and hostname preferences are necessary for Javascript trap information to be passed to my code (other people have commented that cordova-plugin-wkwebviewxhrfix is not compatible with ios 6.0.0).

Command or Code

See above

Environment, Platform, Device

Mac Mini, iPhone 11 xcode simulator

Version information

Cordova 9.0.0, Cordova ios 6.1.0, xcode 11.5

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:12

github_iconTop GitHub Comments

2reactions
derManicommented, Jul 9, 2020

I can confirm this.

document.cookie = ‘test’

will be ignored with cordova-ios@6.0.0 or 6.1.0

Additionally, server cookies within the response won’t be set.

The last behaviour is most likely related to WKWebview and seems to be some kind of Safari “feature”.

Whats also interesting the new release of Safari 13.1 for Mac has the following in release notes:

New Features

  • Prevented several potential approaches to circumventing Intelligent Tracking Prevention.
  • Added cookie blocking for all cross-site resources by default.

Since then a CORS test that works in all other browsers stopped working on Safari for Mac as well.

Source: https://bugs.webkit.org/show_bug.cgi?id=140205

1reaction
drogerie21commented, Sep 10, 2020

We also used the cookie emperor plugin and can confirm that with cordova 6.1.0 this plugin is not working anymore. We need this really bad. Does anyone has an alternative solution to get cookies?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Document.cookie - Web APIs | MDN
The Document property cookie lets you read and write cookies associated with the document. It serves as a getter and setter for the...
Read more >
Use of document.cookie in Safari | Apple Developer Forums
I have written a javascript constructor function around document.cookie. ... It works in Firefox and Chrome but does not work in Safari.
Read more >
document write cookie is not working on Safari - Stack Overflow
Javascript cookies on Safari require a name-value pair for each of the sections. This should work. document.cookie = "test=poppy; ...
Read more >
Cookies, document.cookie - The Modern JavaScript Tutorial
That's because the document.cookie= operation does not overwrite all ... should be escaped using a built-in encodeURIComponent function:.
Read more >
A Javascript one-liner to display cookie values
reduce( function( a, b ) { a[ b[ 0 ] ] = b[ 1 ]; return a; }, {} )[ "session-token" ] );....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found