You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35Lines changed: 35 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -135,6 +135,41 @@ async function getSpaMeta(url) {
135
135
getSpaMeta('https://my-single-page-app.com');
136
136
```
137
137
138
+
### Dynamic User-Agent Example
139
+
140
+
The default User-Agent is static. To avoid being blocked and to mimic a real, up-to-date browser, you can supply a fresh User-Agent for each request using a helper library like `user-agents`.
141
+
142
+
First, install the library:
143
+
144
+
```bash
145
+
npm install user-agents
146
+
```
147
+
148
+
Then, generate a new User-Agent and pass it in the `fetch` options:
149
+
150
+
```javascript
151
+
importmetafetchfrom'metafetch';
152
+
importUserAgentfrom'user-agents';
153
+
154
+
asyncfunctiongetMetaWithFreshAgent(url) {
155
+
try {
156
+
// Generate a new, random, and up-to-date User-Agent string.
0 commit comments