Google's John Mueller explains how to keep pop-ups out of Search with robots.txt
John Mueller of Google laid out two ways to stop an age verification pop-up from being fetched by Googlebot or used when a page is rendered.

John Mueller of Google explained how to use the robots.txt file to keep pop-ups shown on a site from appearing to Googlebot and in Google Search. He was answering a question posted on Reddit about an age verification notice that a site is legally required to display.
According to Search Engine Roundtable, which reported the exchange on November 3, the pop-up in question is hosted on a different domain and pulled into the page through an API. The person asking wanted to know whether blocking crawling in that other domain's robots.txt would stop Google from rendering the notice.
"That would generally work," Mueller replied. He added that if the pop-up relies on a specific JavaScript file, that file can also be blocked through robots.txt. He did offer one caveat: "if you have a single JS file that does a lot of things, I wouldn't do that."
Option one: block the domain that hosts the pop-up
When a site embeds content from another domain, whether through an iframe or by calling a script, and that domain disallows all crawling in its robots.txt, crawlers that honor the file, such as Googlebot, won't fetch that content and won't use it in rendering. Mueller said this is how many ad services work.
Googlebot doesn't crawl those URLs as standalone pages, but it does try to fetch them while rendering the page. If robots.txt blocks them, the content isn't loaded and can't be used. The thing to watch, he said, is making sure the pages still load without those URLs, which is usually not an issue in a case like this.
Option two: block the script itself
The other option is to block, in the site's own robots.txt, the JavaScript file that loads the pop-up. Mueller used the example of a file named "load-verification-popup.js": once blocked, the script isn't loaded during rendering.
He said that, in his experience, this approach is less common, but it is an alternative. It also becomes the necessary route when there's no way to change the robots.txt of the domain hosting the pop-up. The report notes that there are probably other ways to get the same result, but that this is the approach recommended by someone from Google Search.
For brands that have to show legal notices such as age verification, the guidance offers two ways to keep that content from being used by Google when it renders pages: block the domain the pop-up comes from, or block the specific script that loads it. Either way, it's worth checking that the page still loads without the notice and avoiding blocking a JavaScript file that also handles other functions on the site.
Key questions
Does blocking the pop-up's host domain in robots.txt stop Google from using it?
According to John Mueller, that generally works: Googlebot respects robots.txt, doesn't fetch the blocked content and doesn't use it when rendering the page.
Can I block just the JavaScript file that loads the pop-up?
Yes, if the file is dedicated to that job. Mueller doesn't recommend it when the same JS file handles several other functions.
What should I check before putting the block in place?
Whether the pages still load normally when those URLs aren't fetched, which, according to Mueller, is usually not a problem in this kind of case.
Source: Search Engine Roundtable.