CodeSteps

Python, C, C++, C#, PowerShell, Android, Visual C++, Java ...

How to fix : User-authored JavaScript found on page (Critical issue) ?

User-authored JavaScript found on page, the issue usually we get if there is any “Custom JavaScript” placed inside the AMP version of the web page.

To resolve this issue, follow the below steps.

Step 1. Before we fix the issue, we need to Identify the pages where this “script” is added. For this, the better tool is, Google’s Search Console Tool.

Step 2. From Search Console Tool, click on the Accelerated Mobile Pages link under Search Appearance.

Search Console Tool will display the list of issues, their Severity & numbers of pages with issues.

Step 3.User-authored JavaScript found on page” issue, listed as a Critical issue. By clicking on this, Search Console Tool will display the list of pages having this issue. The URLs you can see under the “AMP URL” column, and also the last detected date displayed under the “Last detected” column.

AMP - User-authored JavaScript found on page - List of AMP URLs
AMP – User-authored JavaScript found on page – List of AMP URLs

Step 4. Now we know what are the pages having this issue. We do the AMP Test and look for the place where exactly the issue is there on the page.

Click on the “AMP URL” from the list. Search Console Tool will display the dialog, to allow us to “Test page”.

Step 5. Click on the “Test page” button. AMP Test page will open and start analyzing the page for issues. AMP Test will display “Not a valid AMP page” and under “User-authored JavaScript found on page”, it also lists out the number of instances where exactly the issue occurred. By clicking on it, it will show clearly wherein the Source Code, the issue has occurred.

AMP Test - Not a valid AMP page
AMP Test – Not a valid AMP page

Step 6. Observe that, the issue is due to the “Custom JavaScript” added on the page: AMP Test results show the line number also, where the custom script has occurred.

Line 405:0     <script src=’/google_analytics_auto.js’></script></head>

Step 7. Now we know what the issue is. We just need to remove the above Custom JavaScript, from the page where this is placed.

  • Verify whether your site’s header page is placing this Custom JavaScript code. If so, remove it.
  • Verify whether “.htaccess” has the substitute entry to place the Custom JavaScript code, whenever the page is loaded. If so, remove the code.

Usually, the code looks like below: You can comment on each line by prefixing “#” or removing the lines from the “.htaccess” file.

# Custom JavaScript - Add
<IfModule mod_substitute.c>
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|(<script src='/google_analytics_auto.js'></script>)?</head>|<script src='/google_analytics_auto.js'></script></head>|i"
</IfModule>

  • Verify if there are any other places, where the Custom JavaScript code is injected. If so, remove the entries or change the configuration to stop injecting the Custom JavaScript code.

Step 8. Now we need to verify whether the changes we did, are working fine. To do this, again go back to the AMP Test page & retest the URL. If everything working fine, you will see:

 Valid AMP page

Page is eligible for AMP search features in Google search results

message on the page.

Step 9. After all the issues are fixed, after some time, once all the pages are re-validated you will see the results in Search Console without any issues reported.

Paul

How to fix : User-authored JavaScript found on page (Critical issue) ?

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top