コレクションでコンテンツを整理 必要に応じて、コンテンツの保存と分類を行います。
検索関連の JavaScript の問題を解決する
このガイドでは、ページ(または JavaScript を使用するページの特定のコンテンツ)が Google 検索結果に表示されない場合、その原因となっている JavaScript の問題を特定して解決する方法を説明します。Google 検索も JavaScript を実行しますが、クローラーによるアクセスやレンダリングに対応するために、ページやアプリケーションを設計する際に考慮しなければならない点や制限事項がいくつかあります。Google 検索向けに JavaScript サイトを最適化する方法について詳しくは、JavaScript SEO の基本に関するガイドをご覧ください。
Googlebot は、ウェブ上の一員として有益な働きができるよう設計されています。その主要な優先事項がクロールです。クロールは、サイトにアクセスするユーザーの利便性を損なわない仕組みになっています。Googlebot とそのウェブ レンダリング サービス(WRS)コンポーネントは、継続的に分析を行うことで、重要なページ コンテンツに貢献しないリソースを特定し、そのようなリソースを取得しない場合があります。たとえば、重要なページ コンテンツに貢献しないレポート作成やエラー要求などのリクエストは、重要なページ コンテンツの抽出に使用されない場合や、不要と判断される場合があります。クライアント側の分析では、サイト上での Googlebot や WRS のアクティビティを、完全に把握できない場合や正確に把握できない場合があります。Googlebot と WRS のアクティビティを確認し、サイトに関するフィードバックを得るには、Google Search Console のクロールの統計情報レポートを使用してください。
Google 検索結果にページ(または JavaScript を使用するページの特定のコンテンツ)が表示されない原因が、JavaScript の問題と考えられる場合は、下記の手順を実施します。JavaScript が主原因かどうか不明な場合は、一般的なデバッグのガイドに沿って問題を特定してください。
- Search Console のリッチリザルト テストまたは URL 検査ツールを使用して、Google による URL のクロールとレンダリングをテストします。読み込まれたリソース、JavaScript コンソールの出力と例外、レンダリングされた DOM、その他の情報を表示できます。
可能であれば、そのサイトのユーザー(Googlebot も含め)で発生した JavaScript エラーの収集と調査を行い、コンテンツのレンダリングに影響しうる問題を特定することもおすすめします。以下に、Global Onerror Handler で取得された JavaScript エラーを記録する方法の例を示します。なお、JavaScript エラーの種類(解析エラーなど)によっては、この方法では記録できません。
window.addEventListener('error', function(e) { var errorText = [ e.message, 'URL: ' + e.filename, 'Line: ' + e.lineno + ', Column: ' + e.colno, 'Stack: ' + (e.error && e.error.stack || '(no stack trace)') ].join('\n'); // Example: log errors as visual output into the host page. // Note: you probably don't want to show such errors to users, or // have the errors get indexed by Googlebot; however, it may // be a useful feature while actively debugging the page. var DOM_ID = 'rendering-debug-pre'; if (!document.getElementById(DOM_ID)) { var log = document.createElement('pre'); log.id = DOM_ID; log.style.whiteSpace = 'pre-wrap'; log.textContent = errorText; if (!document.body) document.body = document.createElement('body'); document.body.insertBefore(log, document.body.firstChild); } else { document.getElementById(DOM_ID).textContent += '\n\n' + errorText; } // Example: log the error to remote service. // Note: you can log errors to a remote service, to understand // and monitor the types of errors encountered by regular users, // Googlebot, and other crawlers. var client = new XMLHttpRequest(); client.open('POST', 'https://example.com/logError'); client.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8'); client.send(errorText); });
soft 404
エラーを確実に防止します。シングルページ アプリケーション(SPA)では特に、ソフト 404 エラーを防止するのが困難な場合があります。エラーページがインデックスに追加されないようにするには、次のいずれかまたは両方を実施します。- サーバーが
404
ステータス コードを返す URL にリダイレクトする。 fetch(`https://api.kitten.club/cats/${id}`) .then(res => res.json()) .then((cat) => { if (!cat.exists) { // redirect to page that gives a 404 window.location.href = '/not-found'; } });
- robots
meta
タグを追加する、または noindex
に変更する。 fetch(`https://api.kitten.club/cats/${id}`) .then(res => res.json()) .then((cat) => { if (!cat.exists) { const metaRobots = document.createElement('meta'); metaRobots.name = 'robots'; metaRobots.content = 'noindex'; document.head.appendChild(metaRobots); } });
SPA がエラーの処理にクライアントサイドの JavaScript を使用している場合、適切なステータス コードではなく、200
HTTP ステータス コードをレポートすることがよくあります。それにより、エラーページがインデックスに登録され、検索結果に表示される可能性があります。
- Googlebot はユーザーへのアクセス許可リクエストを拒否するものと考えます。
アクセス許可を必要とする機能は、Googlebot や一部のユーザーにとっては意味をなしません。たとえば、Camera API
を必須にしたとしても、Googlebot はカメラ機能を提供できません。ユーザーにカメラへのアクセス許可を求めずに、コンテンツにアクセスできるようにします。 - URL フラグメントを使用して別のコンテンツを読み込まないでください。
SPA では別のビューの読み込みに URL フラグメント(https://example.com/#/products など)を使用する場合があります。2015 年以降、AJAX クロールに関するスキームが廃止されたため、Googlebot との連携に URL フラグメントを使用することはできません。History API を使用して、SPA の URL に基づいて別のコンテンツを読み込むことをおすすめします。 - データの保持機能を利用してコンテンツを配信しないでください。
WRS は、通常のブラウザと同じように、サーバーとクライアントのリダイレクトに従って各 URL を読み込みます(Google がコンテンツを検出する方法の概要については、Google 検索の仕組みをご覧ください)。ただし、WRS ではページ読み込み時に状態が保持されません。- ローカル ストレージとセッション ストレージのデータは、ページ読み込み時にクリアされます。
- HTTP Cookie はページ読み込み時にクリアされます。
- コンテンツのフィンガープリントを使用すると、Googlebot のキャッシュに関する問題を回避できます。
Googlebot は、ネットワーク リクエストとリソース使用量を減らすために、積極的にキャッシュに保存しますが、WRS はキャッシュ ヘッダーを無視することがあります。このため、WRS は古い JavaScript や CSS リソースを使用するおそれがあります。この問題は、ファイル名の一部をコンテンツのフィンガープリントにすることで回避されます(main.2bb85551.js
など)。フィンガープリントはファイル コンテンツによって異なるため、更新するたびに別のファイル名が生成されます。詳細については、長期保存キャッシュを使用する際の web.dev ガイドをご覧ください。 - アプリケーションでは、必要なすべての重要 API について機能検出を使用し、フォールバック動作や可能な場合はポリフィルを用意するようにします。
ウェブ機能によっては、まだすべてのユーザー エージェントに採用されていない可能性があり、またエージェントによっては、意図的に特定の機能を無効にしている場合もあります。たとえば、ブラウザでフォト エフェクトをレンダリングするのに WebGL を使用する場合、機能検出により、Googlebot では WebGL がサポートされていないことがわかります。これを解決するため、フォト エフェクトをスキップするか、サーバー側レンダリングを使用してフォト エフェクトを事前にレンダリングしておきます。こうすることで、Googlebot を含むすべてのユーザーがコンテンツにアクセスできるようになります。 - コンテンツが HTTP 接続に対応していることを確認します。
Googlebot は、サーバーからコンテンツを取得するために HTTP リクエストを使用します。WebSockets
や WebRTC
など、他のタイプの接続はサポートされていません。これらのような接続の問題を回避するには、コンテンツを取得するめの HTTP フォールバックを提供し、堅牢なエラー処理と機能検出を使用してください。 - ウェブ コンポーネントのレンダリングが想定どおりに行われていることを確認します。リッチリザルト テストまたは URL 検査ツールを使用して、想定するコンテンツが、レンダリングされた HTML にすべてあるかどうかを確認します。
WRS は、Light DOM と Shadow DOM をフラット化します。お使いのウェブ コンポーネントで Light DOM コンテンツに対し <slot>
メカニズムが使用されていない場合は、ウェブ コンポーネントのドキュメントを参照して詳細を確認するか、別のウェブ コンポーネントを使用します。詳しくは、ウェブ コンポーネントに関するおすすめの方法をご覧ください。 - このチェックリストの項目を解決したら、Search Console のリッチリザルト テストまたは URL 検査ツールを使用してページを再度テストします。
問題が解決した場合は、エラーの代わりに緑色のチェックマークが表示されます。それでもエラーが表示される場合は、検索セントラルのヘルプ コミュニティに投稿してください。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-04 UTC。
[null,null,["最終更新日 2025-08-04 UTC。"],[[["\u003cp\u003eThis guide helps you identify and fix JavaScript issues that may be preventing your website content from appearing correctly in Google Search.\u003c/p\u003e\n"],["\u003cp\u003eUse the Rich Results Test or the URL Inspection Tool to see how Googlebot crawls and renders your web pages, including loaded resources, JavaScript errors, and the rendered DOM.\u003c/p\u003e\n"],["\u003cp\u003eEnsure your single-page application handles soft 404 errors correctly by redirecting to a 404 page or using the noindex meta tag for error pages.\u003c/p\u003e\n"],["\u003cp\u003eAvoid using URL fragments for loading content and rely on the History API instead, and ensure your web components render as expected by using the \u003ccode\u003e<slot>\u003c/code\u003e mechanism for light DOM content.\u003c/p\u003e\n"],["\u003cp\u003eGooglebot has limitations, such as declining permission requests and not supporting data persistence or connections like WebSockets and WebRTC, so design your content accordingly with fallbacks.\u003c/p\u003e\n"]]],["To resolve JavaScript-related search issues, first, test how Google crawls and renders your URLs using the Rich Results Test or URL Inspection Tool. Collect and audit JavaScript errors. Prevent soft 404 errors by redirecting or adding a \"noindex\" meta tag. Avoid relying on user permission requests, URL fragments, or data persistence. Employ content fingerprinting to avoid caching issues. Use feature detection for critical APIs, ensure HTTP connection compatibility, and verify web component rendering. Finally, retest your page after fixes.\n"],null,["Fix Search-related JavaScript problems\n\n\nThis guide helps you identify and fix JavaScript issues that may be blocking your page, or specific content on JavaScript powered pages, from showing up in Google Search.\nWhile Google Search does run JavaScript, there are some differences and limitations that you need to account for when designing your pages and applications to accommodate how crawlers access and render your content.\nOur [guide on JavaScript SEO basics](/search/docs/guides/javascript-seo-basics) has more information on how you can optimize your JavaScript site for Google Search.\n\nGooglebot is designed to be a good citizen of the web. Crawling is its [main priority](/search/blog/2017/01/what-crawl-budget-means-for-googlebot), while making sure it doesn't degrade the experience of users visiting the site.\nGooglebot and its Web Rendering Service (WRS) component continuously analyze and identify resources that don't contribute to essential page content and may not fetch such resources.\nFor example, reporting and error requests that don't contribute to essential page content, and other similar types of requests are unused or unnecessary to extract essential page content. Client-side analytics may not provide a full or accurate representation of Googlebot and WRS activity on your site.\nUse [the crawl stats report in Google Search Console](https://support.google.com/webmasters/answer/9679690) to monitor Googlebot and WRS activity and feedback on your site.\n\n\nIf you suspect that JavaScript issues might be blocking your page, or specific content on JavaScript powered pages, from showing up in Google Search, follow these steps. If you're not sure if JavaScript is the main cause, follow our [general debugging guide](/search/docs/guides/debug) to determine the specific issue.\n\n1. **To test how Google crawls and renders a URL** , use the [Rich Results Test](https://search.google.com/test/rich-results) or the [URL Inspection Tool](https://support.google.com/webmasters/answer/9012289) in Search Console. You can see loaded resources, JavaScript console output and exceptions, rendered DOM, and more information.\n\n\n Optionally, we also recommend collecting and auditing JavaScript errors encountered by users, including Googlebot, on your site to identify potential issues that may affect how content is rendered.\n Here's an example that shows how to log JavaScript errors that are logged in the [global onerror handler](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror). Note that some types of JavaScript errors, such as a parse error, cannot be logged with this method. \n\n ```javascript\n window.addEventListener('error', function(e) {\n var errorText = [\n e.message,\n 'URL: ' + e.filename,\n 'Line: ' + e.lineno + ', Column: ' + e.colno,\n 'Stack: ' + (e.error && e.error.stack || '(no stack trace)')\n ].join('\\n');\n\n // Example: log errors as visual output into the host page.\n // Note: you probably don't want to show such errors to users, or\n // have the errors get indexed by Googlebot; however, it may\n // be a useful feature while actively debugging the page.\n var DOM_ID = 'rendering-debug-pre';\n if (!document.getElementById(DOM_ID)) {\n var log = document.createElement('pre');\n log.id = DOM_ID;\n log.style.whiteSpace = 'pre-wrap';\n log.textContent = errorText;\n if (!document.body) document.body = document.createElement('body');\n document.body.insertBefore(log, document.body.firstChild);\n } else {\n document.getElementById(DOM_ID).textContent += '\\n\\n' + errorText;\n }\n\n // Example: log the error to remote service.\n // Note: you can log errors to a remote service, to understand\n // and monitor the types of errors encountered by regular users,\n // Googlebot, and other crawlers.\n var client = new XMLHttpRequest();\n client.open('POST', 'https://example.com/logError');\n client.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8');\n client.send(errorText);\n\n });\n ```\n2. **Make sure to prevent [`soft 404` errors](/search/docs/crawling-indexing/http-network-errors#soft-404-errors).** In a single-page application (SPA), this can be especially difficult. To prevent error pages from being indexed, you can use one or both of the following strategies:\n - Redirect to a URL where the server responds with a `404` status code. \n\n ```javascript\n fetch(`https://api.kitten.club/cats/${id}`)\n .then(res =\u003e res.json())\n .then((cat) =\u003e {\n if (!cat.exists) {\n // redirect to page that gives a 404\n window.location.href = '/not-found';\n }\n });\n ```\n - Add or change the robots `meta` tag to `noindex`. \n\n ```javascript\n fetch(`https://api.kitten.club/cats/${id}`)\n .then(res =\u003e res.json())\n .then((cat) =\u003e {\n if (!cat.exists) {\n const metaRobots = document.createElement('meta');\n metaRobots.name = 'robots';\n metaRobots.content = 'noindex';\n document.head.appendChild(metaRobots);\n }\n });\n ```\n\n\n When a SPA is using client-side JavaScript to handle errors they often report a `200` HTTP status code instead of the [appropriate status code](/search/docs/crawling-indexing/javascript/javascript-seo-basics#use-meaningful-http-status-codes). This can lead to error pages being indexed and possibly shown in search results.\n3. **Expect Googlebot to decline [user permission requests](https://w3c.github.io/permissions/#permission-registry).** \n Features that require user permission don't make sense for Googlebot, or for all users. For example, if you make the `Camera API` required, Googlebot can't provide a camera to you. Instead, provide a way for users to access your content without being forced to allow camera access.\n4. **Don't use URL fragments to load different content.** \n A SPA may use URL fragments (for example https://example.com/#/products) for loading different views. The [AJAX-crawling scheme has been deprecated](/search/blog/2015/10/deprecating-our-ajax-crawling-scheme) since 2015, so you can't rely on URL fragments to work with Googlebot. We recommend using the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History) to load different content based on the URL in a SPA.\n5. **Don't rely on data persistence to serve content.** \n WRS loads each URL (refer to [How Google Search Works](/search/docs/fundamentals/how-search-works) for an overview of how Google discovers content), following server and client redirects, same as a regular browser. However, WRS does not retain state across page loads:\n - Local Storage and Session Storage data are cleared across page loads.\n - HTTP Cookies are cleared across page loads.\n6. **Use content fingerprinting to avoid caching issues with Googlebot.** \n Googlebot caches aggressively in order to reduce network requests and resource usage. WRS may ignore caching headers. This may lead WRS to use outdated JavaScript or CSS resources. Content fingerprinting avoids this problem by making a fingerprint of the content part of the filename, like `main.2bb85551.js`. The fingerprint depends on the content of the file, so updates generate a different filename every time. Check out the [web.dev guide on long-lived caching strategies](https://web.dev/articles/http-cache#versioned-urls) to learn more.\n7. **Ensure that your application uses [feature detection](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Feature_detection) for all critical APIs that it needs and provide a fallback behavior or polyfill where applicable.** \n Some web features may not yet be adopted by all user agents and some may intentionally disable certain features. For example, if you use WebGL to render photo effects in the browser, feature detection shows that Googlebot doesn't support WebGL. To fix this, you could skip the photo effect or decide to use server-side rendering to prerender the photo effects, which makes your content accessible to everyone, including Googlebot.\n8. **Make sure your content works with HTTP connections.** \n Googlebot uses HTTP requests to retrieve content from your server. It does not support other types of connections, such as [WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) or [WebRTC](https://developer.mozilla.org/en-US/docs/Glossary/WebRTC) connections. To avoid problems with such connections, make sure to provide an HTTP fallback to retrieve content and use robust error handling and [feature detection](#feature-detection).\n9. **Make sure your web components render as expected.** Use the [Rich Results Test](https://search.google.com/test/rich-results) or the [URL Inspection Tool](https://support.google.com/webmasters/answer/9012289) to check if the rendered HTML has all content you expect. \n WRS flattens the [light DOM and shadow DOM](/web/fundamentals/web-components/shadowdom#lightdom). If the web components you use aren't using [`\u003cslot\u003e` mechanism](/web/fundamentals/web-components/shadowdom#slots) for light DOM content, consult the documentation of the web component for further information or use another web component instead. For more information, see [best practices for web components](/search/docs/guides/javascript-seo-basics#web-components).\n10. **After you fix the items in this checklist, test your page** with the [Rich Results Test](https://search.google.com/test/rich-results) or the [URL inspection tool](https://search.google.com/search-console) in Search Console again.\n\n If you fixed the issue, a green check mark appears and no errors display. If you still see errors, post in the [Search Central help community](https://support.google.com/webmasters/community)."]]