In a Drupal 10 site I have a page (content type: Basic page) that needs a small Javascript fragment defined in a Javascript file that was added as an asset to the theme.libraries.yml file. I don't want to provide the Javascript through the theme.info.yml file because it would be included in every page served by the site.
Instead, I would like to include it only in that specific page. Various sources of information suggest implementing the hook hook_page_attachments_alter. From what I can see, this hook is called with every request. How can I check inside the hook if the request is for the page that needs the Javascript fragment? I do not want to use the URL or the node id. Instead I would like to use the title field of the node.
Thank you.