curl with cookies
|
|
||
|---|---|---|
| .forgejo/workflows | ||
| .gitignore | ||
| .npmignore | ||
| index.js | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| test.js | ||
curlwc
curl with cookies - A tool to retrieve cookies and CSRF tokens from Chromium and use them with curl.
Security Warning
This tool launches Chromium with remote debugging enabled on port 9222 without authentication. While the debugging interface is only accessible via localhost, it still allows any local process to access your browser's debugging interface and potentially access your cookies and browser data. Use this tool only for development purposes.
Usage
curlwc <url|current> [curl_args...]
or
curlwc browser [profile_dir]
Options
<url|current>: The URL to retrieve cookies and CSRF tokens from, or 'current' to use the active tab.[curl_args...]: Additional arguments to pass to curl.
Default Profile
The default profile directory is ~/.dev-chrome-profile.
Manual Browser Launch
To launch Chromium manually, use:
chromium --remote-debugging-port=9222 --user-data-dir=[profile_path]
Replace [profile_path] with the path to the profile directory.
Example
Let's say you want to check some responses that need login on your local development server. Start by starting the debug browser:
curlwc browser /tmp/dev-browser-profile
By default ~/.dev-chrome-profile is used as profile dir.
Login to your app. Now you can use curlwc to "curl" your app as a logged in user:
curlwc http://localhost:8080 -L -o /dev/null -v
The current active page can be used with curlwc current [...].
If the current active page contains a "CSRF Token" meta Tag, its content attribute's value is provided to curl as a HTTP header.
To save the cookies in a jar for other uses, provide -c cookieJar.txt.
This tells curl to save all cookies to this file.
Install
sudo npm i -g curlwc