Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to the Power Users community on Codidact!

Power Users is a Q&A site for questions about the usage of computer software and hardware. We are still a small site and would like to grow, so please consider joining our community. We are looking forward to your questions and answers; they are the building blocks of a repository of knowledge we are building together.

Post History

75%
+4 −0
Q&A Setting a cookie with a userscript

Background: I'm using a websites which uses a pin code locally stored in a cookie for login. As firefox does not recognise the field to input the pin as a password field, it won't store the passwo...

2 answers  ·  posted 1y ago by samcarter‭  ·  last activity 1y ago by samcarter‭

#1: Initial revision by user avatar samcarter‭ · 2022-10-06T10:06:39Z (over 1 year ago)
Setting a cookie with a userscript
### Background:

I'm using a websites which uses a pin code locally stored in a cookie for login. As firefox does not recognise the field to input the pin as a password field, it won't store the password for me. 

To avoid having to remember the pin myself, I'm using a greasemonkey user script to automatically set the cookie (security is not a concern, the website in question does not hold any important or personal information, so I don't mind that the pin is stored as plain text on my computer)

The user script I'm currently using looks like this:

```
// ==UserScript==
// @name         test
// @match        *://example.com/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
'use strict';

    document.cookie = "uuid=xxx";
    
})();
```

### Problem:

The above user script works fine on the second time. On the first time I open the website I won't be logged in, but if I reload the site or open a second tab, I'm logged in. So apparently the cookie is correctly created, but too late. 

Is there a way to create the cookie earlier?

---

I'm using
- greasemonkey 4.11
- firefox 102.3.0ESR
- macOS 11.6.8