Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions snippets/whitelabel/ai/batches/id.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```shell
curl -H "Authorization: Bearer $MASSIVE_TOKEN" \
'https://render.joinmassive.com/ai/batches'\
'?id=b3829f53-abc9-4e62-8a65-2d9359d586d6'
```
15 changes: 15 additions & 0 deletions snippets/whitelabel/ai/batches/prompts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```shell
curl -X POST 'https://render.joinmassive.com/ai/batches' \
-H "Authorization: Bearer $MASSIVE_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"prompts": [
"Where can I buy a vintage guitar?",
"Help me find guitar repair shops nearby.",
"Do any local stores sell vinyl records?",
"[Additional prompts here]"
],
"country": "US",
"subdivision": "TN"
}'
```
5 changes: 5 additions & 0 deletions snippets/whitelabel/ai/completions.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```shell
curl -H "Authorization: Bearer $MASSIVE_TOKEN" \
'https://render.joinmassive.com/ai/batches'\
'?id=b3829f53-abc9-4e62-8a65-2d9359d586d6'
```
4 changes: 2 additions & 2 deletions snippets/whitelabel/ai/device.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```shell
curl -H "Authorization: Bearer $MASSIVE_TOKEN" \
'https://render.joinmassive.com/ai'\
'?prompt=what+happened+to+blackberry'\
'&device=blackberry+playbook'
'?prompt=What+happened+to+blackberry%3F'\
'&device=Blackberry+PlayBook'
```
4 changes: 1 addition & 3 deletions snippets/whitelabel/ai/expiration.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
### Cachebusting

```shell
curl -H "Authorization: Bearer $MASSIVE_TOKEN" \
'https://render.joinmassive.com/ai'\
'?prompt=current+weather'\
'?prompt=Show+the+current+weather.'\
'&expiration=0'
```
2 changes: 1 addition & 1 deletion snippets/whitelabel/ai/id.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```shell
curl -H "Authorization: Bearer $MASSIVE_TOKEN" \
'https://render.joinmassive.com/ai/completions'\
'https://render.joinmassive.com/ai'\
'?id=1851dab8-4619-409f-893f-47dd3a180bc3'
```
2 changes: 1 addition & 1 deletion snippets/whitelabel/ai/mode.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```shell
curl -H "Authorization: Bearer $MASSIVE_TOKEN" \
'https://render.joinmassive.com/ai'\
'?prompt=prolonged+fasting'\
'?prompt=Summarize+the+latest+research+on+prolonged+fasting.'\
'&mode=async'
```
6 changes: 3 additions & 3 deletions snippets/whitelabel/ai/subdivision.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
```shell
curl -H "Authorization: Bearer $MASSIVE_TOKEN" \
'https://render.joinmassive.com/ai'\
'?prompt=find+vintage+guitar+stores'\
'&country=us'\
'&subdivision=tn'
'?prompt=Where+can+I+buy+a+vintage+guitar%3F'\
'&country=US'\
'&subdivision=TN'
```
5 changes: 5 additions & 0 deletions snippets/whitelabel/browser/batches/id.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```shell
curl -H "Authorization: Bearer $MASSIVE_TOKEN" \
'https://render.joinmassive.com/browser/batches'\
'?id=cfde9b46-f599-49ab-844e-9b2461285284'
```
15 changes: 15 additions & 0 deletions snippets/whitelabel/browser/batches/urls.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```shell
curl -X POST 'https://render.joinmassive.com/browser/batches' \
-H "Authorization: Bearer $MASSIVE_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"urls": [
"https://guitars.com/",
"https://cartervintage.com/",
"https://musiccityvintageguitars.com/",
"[Additional URLs here]"
],
"country": "US",
"city": "Nashville"
}'
```
107 changes: 107 additions & 0 deletions snippets/whitelabel/browser/cdp/cdp2rest.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
```js
#!/usr/bin/env node
import puppeteer from 'puppeteer';

const cdpEndpoint = 'wss://render.joinmassive.com/browser';
const restEndpoint = 'https://render.joinmassive.com/browser';
const apiToken = process.env.MASSIVE_TOKEN;
const sessionId = Date.now();
const headers = {
Authorization: `Bearer ${apiToken}`,
Cookie: `session=${sessionId}`
};
const orderUrl = 'https://httpbin.org/forms/post';
const receiptUrl = 'https://httpbin.org/post';
const sizeSelector = '[name="size"][value="medium"]';
const toppingSelector = '[name="topping"][value="onion"]';
const buttonSelector = 'button';
const timeoutMs = 180_000;
const delayMs = 1_000;

console.log(`Connecting via CDP with session ${sessionId} ...`);

const browser = await puppeteer.connect({
browserWSEndpoint: cdpEndpoint,
headers
});
const [page] = await browser.pages();
let response = await page.goto(orderUrl);

if (response?.ok()) {
console.log(`"${await page.title()}" interacted with successfully`);
} else {
console.error(
'Page interaction failure:',
await page.evaluate(() => {
return document.body.innerText;
})
);

process.exit(1);
}

await page.waitForSelector(sizeSelector);
await page.click(sizeSelector);
await new Promise((resolve) => {
setTimeout(resolve, delayMs);
});
await page.waitForSelector(toppingSelector);
await page.click(toppingSelector);
await new Promise((resolve) => {
setTimeout(resolve, delayMs);
});
await page.waitForSelector(buttonSelector);
await Promise.all([
page.waitForNavigation({ waitUntil: 'domcontentloaded' }),
page.click(buttonSelector)
]);
await browser.disconnect();

console.log(`Making REST request with session ${sessionId} ...`);

const controller = new AbortController();
const timeoutId = setTimeout(() => {
controller.abort();
}, timeoutMs);

try {
response = await fetch(
`${restEndpoint}?url=${encodeURIComponent(receiptUrl)}&expiration=0`,
{ headers, signal: controller.signal }
);
} catch (error) {
const hasTimedOut = error.name == 'AbortError';
response = new Response(
hasTimedOut ? 'Request timed out' : 'Unknown error occurred',
{ status: hasTimedOut ? 504 : 500 }
);
} finally {
clearTimeout(timeoutId);
}

if (response.ok) {
const data = await response.json();

if (
data.form &&
typeof data.form.size == 'string' &&
typeof data.form.topping == 'string'
) {
console.log(
'Ordered ' +
data.form.size.toLowerCase() +
' pizza with ' +
data.form.topping.toLowerCase() +
' successfully'
);
} else {
console.error('Receipt was malformed');

process.exit(1);
}
} else {
console.error('Order form read failure:', (await response.text()).trimEnd());

process.exit(1);
}
```
3 changes: 3 additions & 0 deletions snippets/whitelabel/browser/cdp/close.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```py
browser.close()
```
10 changes: 10 additions & 0 deletions snippets/whitelabel/browser/cdp/device.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
```js
const browser = await puppeteer.connect({
browserWSEndpoint:
'wss://render.joinmassive.com/browser' +
'?device=Blackberry+Playbook',
headers: {
Authorization: `Bearer ${process.env.MASSIVE_TOKEN}`
}
});
```
10 changes: 10 additions & 0 deletions snippets/whitelabel/browser/cdp/difficulty.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
```js
const browser = await puppeteer.connect({
browserWSEndpoint:
'wss://render.joinmassive.com/browser' +
'?difficulty=medium',
headers: {
Authorization: `Bearer ${process.env.MASSIVE_TOKEN}`
}
});
```
3 changes: 3 additions & 0 deletions snippets/whitelabel/browser/cdp/disconnect.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```js
await browser.disconnect();
```
26 changes: 26 additions & 0 deletions snippets/whitelabel/browser/cdp/e2e.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
```py
#!/usr/bin/env python3
import os
from playwright.sync_api import sync_playwright

ENDPOINT = 'wss://render.joinmassive.com/browser'
API_TOKEN = os.environ['MASSIVE_TOKEN']
URL = 'https://example.com/'

print(f"Connecting to {ENDPOINT} ...")

with sync_playwright() as playwright:
browser = playwright.chromium.connect_over_cdp(
ENDPOINT,
headers={'Authorization': f"Bearer {API_TOKEN}"}
)
context = browser.contexts[0]
page = context.pages[0]

print(f"Going to {URL} ...")

page.goto(URL)
print(f"URL: {page.url}")
print(f"Title: {page.title()}")
browser.close()
```
7 changes: 7 additions & 0 deletions snippets/whitelabel/browser/cdp/goto.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```js
const [page] = await browser.pages();

await page.goto('https://example.com/');
console.log('URL:', page.url());
console.log('Title:', await page.title());
```
14 changes: 14 additions & 0 deletions snippets/whitelabel/browser/cdp/playwright.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```py
#!/usr/bin/env python3
import os
from playwright.sync_api import sync_playwright

with sync_playwright() as playwright:
browser = playwright.chromium.connect_over_cdp(
'wss://render.joinmassive.com/browser',
headers={
'Authorization':
f"Bearer {os.environ['MASSIVE_TOKEN']}"
}
)
```
11 changes: 11 additions & 0 deletions snippets/whitelabel/browser/cdp/puppeteer.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```js
#!/usr/bin/env node
import puppeteer from 'puppeteer';

const browser = await puppeteer.connect({
browserWSEndpoint: 'wss://render.joinmassive.com/browser',
headers: {
Authorization: `Bearer ${process.env.MASSIVE_TOKEN}`
}
});
```
Loading