Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update persist-session-state.mdx #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 85 additions & 1 deletion docs/guides/persist-session-state.mdx
Original file line number Diff line number Diff line change
@@ -9,6 +9,9 @@ allows you to resume sessions without requiring the user to open up web pages or
authenticate again.

<Note>
Ensure you contact us at [email protected] to enable the pesistence feature
for your API key.

Want to jump into the code? See our [persistence
example.](https://github.com/hyperbeam/examples/tree/master/persistence)
</Note>
@@ -59,7 +62,7 @@ when [starting a Chromium session](/rest-api/dispatch/start-chromium-session).

### Example Request:

```curl

curl --request POST \
--url https://engine.hyperbeam.com/v0/vm \
--header 'Authorization: Bearer AUTH_VALUE' \
@@ -71,6 +74,87 @@ curl --request POST \
}'
```

## Standard Usage Example

``` // Server
const response = await axios.post("https://engine.hyperbeam.com/v0/vm", {
profile: "sessionID" // Pass the session ID to load the session and overwrite it when the session is over"

}, { headers });
```

## Standard CURL Example
```
1 ~ curl -X POST \
-H "Authorization: Bearer $HB_API_KEY" \
https://engine.hyperbeam.com/v0/vm --data '{"profile": true}'
{"session_id":"1d2df225-e1c5-4d94-8b95-1c6e75ef04ea","embed_url":"https://ctowmpnrcyxcvk1dnrgwgwp74.hyperbeam.com/HS3yJeHFTZSLlRxude8E6g?token=Ah1BDpMQZLaBQ_SAOA8E72jSjPVG1yMtElmm8dUBLjE","admin_token":"PgnA79dfr2QqYLLJvDu5PvibvbcsGlx8n264s6ufA0g"}
2 ~ curl -X DELETE \
-H "Authorization: Bearer $HB_API_KEY" \
https://engine.hyperbeam.com/v0/vm/1d2df225-e1c5-4d94-8b95-1c6e75ef04ea
{"session_id":"1d2df225-e1c5-4d94-8b95-1c6e75ef04ea"}
3 ~ curl -X POST \
-H "Authorization: Bearer $HB_API_KEY" \
https://engine.hyperbeam.com/v0/vm --data '{"profile": "1d2df225-e1c5-4d94-8b95-1c6e75ef04ea"}'
{"session_id":"85ed5c92-8ac3-4bd6-95b5-cd9ea5cab55a","embed_url":"https://ctowmpnrcyxcvk1dnrgwgwp74.hyperbeam.com/he1ckorDS9aVtc2epcq1Wg?token=J5O9fkTaqO2DuELAk-GtumxQ-1_qeCVJzlIJTfs13Jo","admin_token":"LbGxVjbqTjNjkjtGXN5QH_4qMx7AAE7y9a58JLDH09w"}

1. Profile: true -> Make sure to save a new profile
2. Delete the session
3. Pass 1d2df225-e1c5-4d94-8b95-1c6e75ef04ea (the session id from step 1) to load the profile, and also overwrite it when the session is over
```
## Advanced Usage Example

```
// Server
const response = await axios.post("https://engine.hyperbeam.com/v0/vm", {
profile: {
load: "1d2df225-e1c5-4d94-8b95-1c6e75ef04ea" // Load the last session state
save: "1d2df225-e1c5-4d94-8b95-1c6e75ef04ea" // Overwrite the current session state
}
}, { headers });
```

## Advanced cURL example

```
1 ~ curl -X POST \
-H "Authorization: Bearer $HB_API_KEY" \
https://engine.hyperbeam.com/v0/vm --data '{"profile":{"save": true}}'
{"session_id":"5dd3715d-bbf3-4be6-9b55-575201b9c649","embed_url":"https://ctowmpnrcyxcvk1dnrgwgwp74.hyperbeam.com/XdNxXbvzS-abVVdSAbnGSQ?token=BHF0uyT5Z01gNonsi7LTbg0kjMBAKidp4uo0pkg8Rso","admin_token":"WyiZJ8OdjqDK5zZrd79tU8LfSGLYl24R1wLHIZPhmlE"}
2 ~ curl -X DELETE \
-H "Authorization: Bearer $HB_API_KEY" \
https://engine.hyperbeam.com/v0/vm/5dd3715d-bbf3-4be6-9b55-575201b9c649
{"session_id":"5dd3715d-bbf3-4be6-9b55-575201b9c649"}
3 ~ curl -X POST \
-H "Authorization: Bearer $HB_API_KEY" \
https://engine.hyperbeam.com/v0/vm --data '{"profile":{"save": "5dd3715d-bbf3-4be6-9b55-575201b9c649", "load": "5dd3715d-bbf3-4be6-9b55-575201b9c649"}}'
{"session_id":"d2a5c0a6-58c9-4747-a887-1b6b7eaf0db5","embed_url":"https://ctowmpnrcyxcvk1dnrgwgwp74.hyperbeam.com/0qXApljJR0eohxtrfq8NtQ?token=6olWyzf_t4G2rZWfW1KiLArBDE_vw7Qih0n8tgOcGe0","admin_token":"HB0EZrtJtMVQ2HbpXcNz_3hgLbBmU3c_xvXeWkAnfP4"}

1. Create a session, and save it using save: true (create a new save)
2. Delete the session
3. Create a session, with save and load both set to the session ID of the original session. Setting load to the session ID saves it, and setting save to the session id overwrites it.
```

## Steps

```
Contact [email protected] to change your API permissions to enable persistence.
Use npm install to install the dependencies altogether and navigate to the examples you want to run for more information.
Set your API key by running the following command in your terminal:
## Notes

# Linux/macOS
export HB_API_KEY=your_api_key

# Windows
set HB_API_KEY=your_api_key
Replace your_api_key with your API key from the Hyperbeam dashboard.

Run npm run start, a server should be listening on port 8081.

Open http://localhost:8081 on your browser. You should be able to see the browser data being saved and accessed across multiple sessions.
```

## How Do We Persist Sessions?

When `profile.save` is set to `true`, we encrypt and store the Chrome profile of the session in Amazon S3.