• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to use cookies for CEP panel

Engaged ,
Jul 22, 2019 Jul 22, 2019

Copy link to clipboard

Copied

Hi,

Can anyone show a basic example of writing and reading cookies values for the panel?

I want to store the user settings and i could not find any example for it, though I ma still searching.

Thank you,

Views

4.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 23, 2019 Jul 23, 2019

Check below snippets. It might help your work.

//Set session cookie

document.cookie =  "testCookie="+"testStrings"; //Key and Value

//Set persistent cookie

var dt = new Date();

dt.setTime(dt.getTime() + (30*24*60*60*1000));

var ce = "; expires=" + dt.toGMTString(); //persistent cookie needs expires time

var val = "persistentCookie="+"testStrings";

document.cookie = val + ce;

//Get cookies

alert(document.cookie);

//Set and Get localstorage

localStorage.setItem('storageTestKey', "StringFromLocalStorage");

loca

...

Votes

Translate

Translate
Participant ,
Jul 22, 2019 Jul 22, 2019

Copy link to clipboard

Copied

We're using a jquery extension "jquery cookie". Makes setting a cookie easier.
Set the cookie:
var myVar = "something";
$.cookie("xyz", myVar, { path: '/', expires: 365})

Remove the cookie:
$.cookie("xyz", "",{ path: '/', expires: -1})

Thomas

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 22, 2019 Jul 22, 2019

Copy link to clipboard

Copied

Thank,

Do i define the path for the cookie?

If yes, is it: "C:\Users\<USERNAME>\AppData\Local\Temp\cep_cache\"?

On this page:

https://github.com/Adobe-CEP/CEP-Resources/blob/master/CEP_8.x/Documentation/CEP%208.0%20HTML%20Exte...

it says, regarding cookie location:

  • CEP 6.x and later releases
    • Windows: C:\Users\<USERNAME>\AppData\Local\Temp\cep_cache\
    • Mac: /Users/<USERNAME>/Library/Caches/CSXS/cep_cache/

Each persistent cookie is a file. File name is HostID_HostVersion_ExtensionName, such as PHXS_15.0.0_com.adobe.extension1.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 22, 2019 Jul 22, 2019

Copy link to clipboard

Copied

Yes, this is where the cookie is technically stored but this doesn't matter for the creation of the cookie. CEP takes care of storing it in the right file.

The 'path' attribute signifies the URL or path for which the cookie is valid. The default path attribute is set as '/'. This is not the path where the cookie is physically stored. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 22, 2019 Jul 22, 2019

Copy link to clipboard

Copied

Thanks,

Is there by any chance a function which stores/restores all required user input field?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Which event is triggered by closing the panel?

I want to run a function which saves the session cookies when the panel is closed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Check below snippets. It might help your work.

//Set session cookie

document.cookie =  "testCookie="+"testStrings"; //Key and Value

//Set persistent cookie

var dt = new Date();

dt.setTime(dt.getTime() + (30*24*60*60*1000));

var ce = "; expires=" + dt.toGMTString(); //persistent cookie needs expires time

var val = "persistentCookie="+"testStrings";

document.cookie = val + ce;

//Get cookies

alert(document.cookie);

//Set and Get localstorage

localStorage.setItem('storageTestKey', "StringFromLocalStorage");

localStorage.getItem('storageTestKey');

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

Do you know how to save settings when i collapse the panel?

I tried

    new csInterface.addEventListener("com.adobe.csxs.events.ExtensionUnloaded", function(event) { ...

But it did not help, or i did not use it properly.

I searched for this and could not understand whether it is possible to detect when the panel is collapsed or not.

Dan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

What app are you targeting?

Do you want to keep panel contents until application quit?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

I am using Photoshop and i want to keep the settings even when Photoshop restarts.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

If you want to keep contents until close Photoshop app, set persistent event when your extension initializes.

var csi = new CSInterface();

var event = new CSEvent("com.adobe.PhotoshopPersistent", "APPLICATION");

event.extensionId = csi.getExtensionID(); //csInterface define outside function(global).

csi.dispatchEvent(event);

Photoshop doesn't support "applicationBeforeQuit" event. Therefore you need to save each time when your form changed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

Thank you,

If that means that it will be saved each time the form changes, as you suggest, then i'll attach the save cookies to my main action button.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 24, 2019 Jul 24, 2019

Copy link to clipboard

Copied

I think localStorage is better to use.

Here is an example:

HTML form

<input type="text" name="txt" value="Hello" onchange="storeLocal(this.value)">

JavaScript/ When Text field changed...

function storeLocal (val) {

  localStorage.setItem('formTxt', val);

  }

Run once, when Extension loaded...n once, when Extension loaded.

function init() {

  document.getElementById("txt").value = localStorage.getItem('formTxt');

  }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 25, 2020 Mar 25, 2020

Copy link to clipboard

Copied

Tried this and get this error in return

 

 

Uncaught TypeError: Cannot set property 'value' of null

 


EDIT
Quick Googked helped, the input has no ID so i added an id. Now works indeed. But it only works when that get is on the index page, not when i add it to main.js file which has all the code for the panel. Than i get an error again about value. This is nice.

Still wonder then how that cep_cache works and different this is or what we can do with that. I know regular scripts can write some sort of cache so its read back when dialog windows show. So much to learn.... not so much time


Edit 2

well not sure what happened, but it does work from main.js i guess it i didn't do a refresh. can we also store a son file locally or so. I guess using that for settings is easier.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 13, 2020 Aug 13, 2020

Copy link to clipboard

Copied

LATEST

Mopved from D&I to Exchange to hopefully get an answer

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 25, 2020 Mar 25, 2020

Copy link to clipboard

Copied

Can i ask where this is stored? I get the popup but i don't see cep_cache folder appear. Ive also enabled --persist-session-cookies in the manifest
```

<CEFCommandLine>
<Parameter>--persist-session-cookies</Parameter>
</CEFCommandLine>
````

I get the popup with the date and all, but where is this localStorage actually?
 
Ps the code also had an error it is "gExtensionId" solo nothing needs to go before. 
Ive seen this same code in the oersistance panel test from David Barranca  It only stores as long as photoshop is open. But like always, their documentation about session cookies is vague, at least for me it is. Hardly any info

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines