Bookmark Guide
Bookmark is a session-based utility for preserving user intent across redirects, authentication boundaries, and interrupted workflows. This guide
documents the full API, expected behavior, and real-world usage patterns.
Getting Started
Include the Bookmark script once. A global Bookmark object becomes available immediately and initializes lazily on first use.
<script src="https://bookmark.refreshing.cc"></script>
Bookmark stores data in sessionStorage. Data is isolated to the current tab and cleared automatically when the session ends.
How Bookmark Works
Bookmark stores key-value pairs (typically URLs) in session memory. You explicitly control when values are saved, retrieved, redirected to, or
cleared.
- Session-scoped and tab-isolated
- Supports multiple concurrent bookmarks
- No cookies, no server state
- Safe for multi-step flows
API Reference
Bookmark.add(key, value)
Stores or updates a bookmark.
// Usage
Bookmark.add("postLogin", "/dashboard");
// Stored state
[
{ key: "postLogin", value: "/dashboard" }
]
Bookmark.get(key)
Retrieves a value without redirecting.
// Usage
const url = Bookmark.get("postLogin");
// Output
"/dashboard"
Bookmark.go(key)
Redirects to the stored value and removes it immediately, ensuring bookmarks are single-use by default.
// Usage
Bookmark.go("postLogin");
// Behavior
// window.location.href = "/dashboard"
// Bookmark removed from session storage
Bookmark.remove(key)
Deletes a bookmark without redirecting.
// Usage
Bookmark.remove("postLogin");
// Stored state
[]
Bookmark.removeAll()
Clears all bookmarks for the current session.
// Usage
Bookmark.removeAll();
// Stored state
[]
Bookmark.all()
Returns a copy of all stored bookmarks.
// Usage
const bookmarks = Bookmark.all();
// Output
[
{ key: "postLogin", value: "/dashboard" },
{ key: "checkoutStep", value: "/checkout/shipping" }
]
Common Usage Patterns
Return After Login
// Before redirecting to login
Bookmark.add("afterAuth", window.location.href);
window.location.href = "/login";
// After successful authentication
Bookmark.go("afterAuth");
Multi-Step Workflow Recovery
// Save progress
Bookmark.add("checkout", "/checkout/payment");
// Restore later
const step = Bookmark.get("checkout");
if (step) {
window.location.href = step;
}
Intent Preservation
// Capture intent
Bookmark.add("intent", "/pricing");
window.location.href = "/signup";
// Resume intent
Bookmark.go("intent");
Advanced Pattern: Conditional Resume
const bookmarks = Bookmark.all();
if (bookmarks.length === 1) {
Bookmark.go(bookmarks[0].key);
} else if (bookmarks.length > 1) {
// Resolve based on priority or application logic
console.log("Multiple pending intents", bookmarks);
}
Best Practices
- Use descriptive keys (
postLogin, checkout)
- Treat bookmarks as single-use intents
- Store navigation targets only
- Clear bookmarks when workflows are abandoned
Bookmark is purpose-built to preserve user intent and maintain continuity across redirects, authentication boundaries, and interrupted workflows.