main.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const { app, session } = require('electron');
  2. app.whenReady().then(async function () {
  3. const url = 'http://foo.bar';
  4. const persistentSession = session.fromPartition('persist:ence-test');
  5. const name = 'test';
  6. const value = 'true';
  7. const set = () => persistentSession.cookies.set({
  8. url,
  9. name,
  10. value,
  11. expirationDate: Math.floor((Date.now() + 60000) / 1000),
  12. sameSite: 'strict'
  13. });
  14. const get = () => persistentSession.cookies.get({
  15. url
  16. });
  17. const maybeRemove = async (pred) => {
  18. if (pred()) {
  19. await persistentSession.cookies.remove(url, name);
  20. }
  21. };
  22. try {
  23. await maybeRemove(() => process.env.PHASE === 'one');
  24. const one = await get();
  25. await set();
  26. const two = await get();
  27. await maybeRemove(() => process.env.PHASE === 'two');
  28. const three = await get();
  29. process.stdout.write(`${one.length}${two.length}${three.length}`);
  30. } catch (e) {
  31. process.stdout.write(`ERROR : ${e.message}`);
  32. } finally {
  33. process.stdout.end();
  34. app.quit();
  35. }
  36. });