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 bot detection list and add support for oxygen-do-not-stream-response header #2514

Merged
merged 2 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/happy-snails-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen': patch
---

Update bot detection list and add support for oxygen-do-not-stream-response header
5 changes: 4 additions & 1 deletion packages/hydrogen/src/entry-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@ async function processRequest(
});
}

if (isBotUA(url, request.headers.get('user-agent'))) {
if (
request.headers.get('oxygen-do-not-stream-response') === 'true' ||
isBotUA(url, request.headers.get('user-agent'))
) {
response.doNotStream();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {ClientAnalytics} from '../ClientAnalytics.js';
// window.location more than once
describe('Analytics.client utm', () => {
it('should process utm search parameters', async (done) => {
global.window = Object.create(window);
// global.window = Object.create(window);
Object.defineProperty(window, 'location', {
value: {
search:
Expand Down
65 changes: 33 additions & 32 deletions packages/hydrogen/src/utilities/bot-ua.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,56 @@
* https://github.com/GoogleChrome/rendertron/blob/6f681688737846b28754fbfdf5db173846a826df/middleware/src/middleware.ts#L24-L41
*/
const botUserAgents = [
'AdsBot-Google',
'AdsBot-Google-Mobile',
'360spider',
'adsbot-google',
'adsbot-google-mobile',
'applebot',
'Baiduspider',
'baiduspider',
'Bytespider',
'360Spider',
'PetalBot',
'Yisouspider',
'baiduspider',
'bingbot',
'bingbot',
'Bingbot',
'BingPreview',
'bingpreview',
'bitlybot',
'Discordbot',
'DuckDuckBot',
'Embedly',
'bytespider',
'discordbot',
'duckduckbot',
'embedly',
'facebookcatalog',
'facebookexternalhit',
'Google-PageRenderer',
'Googlebot',
'Googlebot-Image',
'Googlebot-News',
'Googlebot-Video',
'google-inspectiontool',
'google-pagerenderer',
'googlebot',
'googlebot-image',
'googlebot-news',
'googlebot-video',
'googleother',
'googleweblight',
'ia_archive',
'LinkedInBot',
'Mediapartners-Google',
'ia_archiver',
'linkedinbot',
'mediapartners-google',
'outbrain',
'petalbot',
'pinterest',
'quora link preview',
'redditbot',
'rogerbot',
'seoradar',
'showyoubot',
'SkypeUriPreview',
'Slackbot',
'Slurp',
'skypeuripreview',
'slackbot',
'slurp',
'sogou',
'Storebot-Google',
'TelegramBot',
'storebot-google',
'telegrambot',
'tumblr',
'Twitterbot',
'vkShare',
'W3C_Validator',
'WhatsApp',
'twitterbot',
'vkshare',
'w3c html2txt',
'w3c_validator',
'whatsapp',
'yandex',

// SEO Tools
'Seoradar',
'W3C html2txt',
'yisouspider',
];

/**
Expand Down