aboutsummaryrefslogtreecommitdiff
path: root/apps/docs/connectors/web-crawler.mdx
blob: 1fb0e18e9dfdf1e84378b9ab072be799758f40a8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
---
title: "Web Crawler Connector"
description: "Crawl and sync websites automatically with scheduled recrawling and robots.txt compliance"
icon: "globe"
---

Connect websites to automatically crawl and sync web pages into your Supermemory knowledge base. The web crawler respects robots.txt rules, includes SSRF protection, and automatically recrawls sites on a schedule.

<Warning>
The web crawler connector requires a **Scale Plan** or **Enterprise Plan**.
</Warning>

## Quick Setup

### 1. Create Web Crawler Connection

<Tabs>
  <Tab title="TypeScript">
    ```typescript
    import Supermemory from 'supermemory';

    const client = new Supermemory({
      apiKey: process.env.SUPERMEMORY_API_KEY!
    });

    const connection = await client.connections.create('web-crawler', {
      redirectUrl: 'https://yourapp.com/callback',
      containerTags: ['user-123', 'website-sync'],
      documentLimit: 5000,
      metadata: {
        startUrl: 'https://docs.example.com'
      }
    });

    // Web crawler doesn't require OAuth - connection is ready immediately
    console.log('Connection ID:', connection.id);
    console.log('Connection created:', connection.createdAt);
    // Note: connection.authLink is undefined for web-crawler
    ```
  </Tab>
  <Tab title="Python">
    ```python
    from supermemory import Supermemory
    import os

    client = Supermemory(api_key=os.environ.get("SUPERMEMORY_API_KEY"))

    connection = client.connections.create(
        'web-crawler',
        redirect_url='https://yourapp.com/callback',
        container_tags=['user-123', 'website-sync'],
        document_limit=5000,
        metadata={
            'startUrl': 'https://docs.example.com'
        }
    )

    # Web crawler doesn't require OAuth - connection is ready immediately
    print(f'Connection ID: {connection.id}')
    print(f'Connection created: {connection.created_at}')
    # Note: connection.auth_link is None for web-crawler
    ```
  </Tab>
  <Tab title="cURL">
    ```bash
    curl -X POST "https://api.supermemory.ai/v3/connections/web-crawler" \
      -H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "redirectUrl": "https://yourapp.com/callback",
        "containerTags": ["user-123", "website-sync"],
        "documentLimit": 5000,
        "metadata": {
          "startUrl": "https://docs.example.com"
        }
      }'

    # Response: {
    #   "id": "conn_wc123",
    #   "redirectsTo": "https://yourapp.com/callback",
    #   "authLink": null,
    #   "expiresIn": null
    # }
    ```
  </Tab>
</Tabs>

### 2. Connection Established

Unlike other connectors, the web crawler doesn't require OAuth authentication. The connection is established immediately upon creation, and crawling begins automatically.

### 3. Monitor Sync Progress

<Tabs>
  <Tab title="TypeScript">
    ```typescript
    // Check connection details
    const connection = await client.connections.getByTags('web-crawler', {
      containerTags: ['user-123', 'website-sync']
    });

    console.log('Start URL:', connection.metadata?.startUrl);
    console.log('Connection created:', connection.createdAt);

    // List synced web pages
    const documents = await client.connections.listDocuments('web-crawler', {
      containerTags: ['user-123', 'website-sync']
    });

    console.log(`Synced ${documents.length} web pages`);
    ```
  </Tab>
  <Tab title="Python">
    ```python
    # Check connection details
    connection = client.connections.get_by_tags(
        'web-crawler',
        container_tags=['user-123', 'website-sync']
    )

    print(f'Start URL: {connection.metadata.get("startUrl")}')
    print(f'Connection created: {connection.created_at}')

    # List synced web pages
    documents = client.connections.list_documents(
        'web-crawler',
        container_tags=['user-123', 'website-sync']
    )

    print(f'Synced {len(documents)} web pages')
    ```
  </Tab>
  <Tab title="cURL">
    ```bash
    # Get connection details by provider and tags
    curl -X POST "https://api.supermemory.ai/v3/connections/web-crawler/connection" \
      -H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"containerTags": ["user-123", "website-sync"]}'

    # Response includes connection details:
    # {
    #   "id": "conn_wc123",
    #   "provider": "web-crawler",
    #   "createdAt": "2024-01-15T10:00:00Z",
    #   "documentLimit": 5000,
    #   "metadata": {"startUrl": "https://docs.example.com", ...}
    # }

    # List synced documents
    curl -X POST "https://api.supermemory.ai/v3/connections/web-crawler/documents" \
      -H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"containerTags": ["user-123", "website-sync"]}'

    # Response: Array of document objects
    # [
    #   {"title": "Home Page", "type": "webpage", "status": "done", "url": "https://docs.example.com"},
    #   {"title": "Getting Started", "type": "webpage", "status": "done", "url": "https://docs.example.com/getting-started"}
    # ]
    ```
  </Tab>
</Tabs>

## Supported Content Types

### Web Pages
- **HTML content** extracted and converted to markdown
- **Same-domain crawling** only (respects hostname boundaries)
- **Robots.txt compliance** - respects disallow rules
- **Content filtering** - only HTML pages (skips non-HTML content)

### URL Requirements

The web crawler only processes valid public URLs:
- Must be a public URL (not localhost, private IPs, or internal domains)
- Must be accessible from the internet
- Must return HTML content (non-HTML files are skipped)

## Sync Mechanism

The web crawler uses **scheduled recrawling** rather than real-time webhooks:

- **Initial Crawl**: Begins immediately after connection creation
- **Scheduled Recrawling**: Automatically recrawls sites that haven't been synced in 7+ days
- **No Real-time Updates**: Unlike other connectors, web crawler doesn't support webhook-based real-time sync

<Note>
The recrawl schedule is automatically assigned when the connection is created. Sites are recrawled periodically to keep content up to date, but updates are not instantaneous.
</Note>

## Connection Management

### List All Connections

<Tabs>
  <Tab title="TypeScript">
    ```typescript
    // List all web crawler connections
    const connections = await client.connections.list({
      containerTags: ['user-123']
    });

    const webCrawlerConnections = connections.filter(
      conn => conn.provider === 'web-crawler'
    );

    webCrawlerConnections.forEach(conn => {
      console.log(`Start URL: ${conn.metadata?.startUrl}`);
      console.log(`Connection ID: ${conn.id}`);
      console.log(`Created: ${conn.createdAt}`);
    });
    ```
  </Tab>
  <Tab title="Python">
    ```python
    # List all web crawler connections
    connections = client.connections.list(container_tags=['user-123'])

    web_crawler_connections = [
        conn for conn in connections if conn.provider == 'web-crawler'
    ]

    for conn in web_crawler_connections:
        print(f'Start URL: {conn.metadata.get("startUrl")}')
        print(f'Connection ID: {conn.id}')
        print(f'Created: {conn.created_at}')
    ```
  </Tab>
  <Tab title="cURL">
    ```bash
    # List all connections
    curl -X POST "https://api.supermemory.ai/v3/connections/list" \
      -H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"containerTags": ["user-123"]}'

    # Response: [
    #   {
    #     "id": "conn_wc123",
    #     "provider": "web-crawler",
    #     "createdAt": "2024-01-15T10:30:00.000Z",
    #     "documentLimit": 5000,
    #     "metadata": {"startUrl": "https://docs.example.com", ...}
    #   }
    # ]
    ```
  </Tab>
</Tabs>

### Delete Connection

Remove a web crawler connection when no longer needed:

<Tabs>
  <Tab title="TypeScript">
    ```typescript
    // Delete by connection ID
    const result = await client.connections.delete('connection_id_123');
    console.log('Deleted connection:', result.id);

    // Delete by provider and container tags
    const providerResult = await client.connections.deleteByProvider('web-crawler', {
      containerTags: ['user-123']
    });
    console.log('Deleted web crawler connection for user');
    ```
  </Tab>
  <Tab title="Python">
    ```python
    # Delete by connection ID
    result = client.connections.delete('connection_id_123')
    print(f'Deleted connection: {result.id}')

    # Delete by provider and container tags
    provider_result = client.connections.delete_by_provider(
        'web-crawler',
        container_tags=['user-123']
    )
    print('Deleted web crawler connection for user')
    ```
  </Tab>
  <Tab title="cURL">
    ```bash
    # Delete by connection ID
    curl -X DELETE "https://api.supermemory.ai/v3/connections/connection_id_123" \
      -H "Authorization: Bearer $SUPERMEMORY_API_KEY"

    # Delete by provider and container tags
    curl -X DELETE "https://api.supermemory.ai/v3/connections/web-crawler" \
      -H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"containerTags": ["user-123"]}'
    ```
  </Tab>
</Tabs>

<Note>
Deleting a connection will:
- Stop all future crawls from the website
- Keep existing synced documents in Supermemory (they won't be deleted)
- Remove the connection configuration
</Note>

## Advanced Configuration

### Content Filtering

Control which web pages get synced using the settings API:

<Tabs>
  <Tab title="TypeScript">
    ```typescript
    // Configure intelligent filtering for web content
    await client.settings.update({
      shouldLLMFilter: true,
      includeItems: {
        urlPatterns: ['*docs*', '*documentation*', '*guide*'],
        titlePatterns: ['*Getting Started*', '*API Reference*', '*Tutorial*']
      },
      excludeItems: {
        urlPatterns: ['*admin*', '*private*', '*test*'],
        titlePatterns: ['*Draft*', '*Archive*', '*Old*']
      },
      filterPrompt: "Sync documentation pages, guides, and API references. Skip admin pages, private content, drafts, and archived pages."
    });
    ```
  </Tab>
  <Tab title="Python">
    ```python
    # Configure intelligent filtering for web content
    client.settings.update(
        should_llm_filter=True,
        include_items={
            'urlPatterns': ['*docs*', '*documentation*', '*guide*'],
            'titlePatterns': ['*Getting Started*', '*API Reference*', '*Tutorial*']
        },
        exclude_items={
            'urlPatterns': ['*admin*', '*private*', '*test*'],
            'titlePatterns': ['*Draft*', '*Archive*', '*Old*']
        },
        filter_prompt="Sync documentation pages, guides, and API references. Skip admin pages, private content, drafts, and archived pages."
    )
    ```
  </Tab>
  <Tab title="cURL">
    ```bash
    # Configure intelligent filtering for web content
    curl -X PATCH "https://api.supermemory.ai/v3/settings" \
      -H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "shouldLLMFilter": true,
        "includeItems": {
          "urlPatterns": ["*docs*", "*documentation*", "*guide*"],
          "titlePatterns": ["*Getting Started*", "*API Reference*", "*Tutorial*"]
        },
        "excludeItems": {
          "urlPatterns": ["*admin*", "*private*", "*test*"],
          "titlePatterns": ["*Draft*", "*Archive*", "*Old*"]
        },
        "filterPrompt": "Sync documentation pages, guides, and API references. Skip admin pages, private content, drafts, and archived pages."
      }'
    ```
  </Tab>
</Tabs>

## Security & Compliance

### SSRF Protection

Built-in protection against Server-Side Request Forgery (SSRF) attacks:
- Blocks private IP addresses (10.x.x.x, 192.168.x.x, 172.16-31.x.x)
- Blocks localhost and internal domains
- Blocks cloud metadata endpoints
- Only allows public, internet-accessible URLs

### URL Validation

All URLs are validated before crawling:
- Must be valid HTTP/HTTPS URLs
- Must be publicly accessible
- Must return HTML content
- Response size limited to 10MB


<Warning>
**Important Limitations:**
- Requires Scale Plan or Enterprise Plan
- Only crawls same-domain URLs
- Scheduled recrawling means updates are not real-time
- Large websites may take significant time to crawl initially
- Robots.txt restrictions may prevent crawling some pages
- URLs must be publicly accessible (no authentication required)
</Warning>