Skip to content

Script v2: Change priority of CSP related error for verifying manual installations#5707

Merged
apata merged 9 commits intomasterfrom
script-v2/find-script-tag
Sep 11, 2025
Merged

Script v2: Change priority of CSP related error for verifying manual installations#5707
apata merged 9 commits intomasterfrom
script-v2/find-script-tag

Conversation

@apata
Copy link
Copy Markdown
Contributor

@apata apata commented Sep 8, 2025

Changes

If the user is verifying a manual installation, CSP error must only be shown after they've actually tried to add the snippet to their site.

Tests

  • Automated tests have been added

Changelog

  • This PR does not make a user-facing change

Documentation

  • This change does not need a documentation update

Dark mode

  • This PR does not change the UI

@apata apata changed the title Script v2/find script tag Script v2: Change priority of CSP related error for verifying manual installations Sep 8, 2025
@apata apata requested a review from RobertJoonas September 8, 2025 12:28
@apata apata force-pushed the script-v2/find-script-tag branch from b89c24a to baa6e35 Compare September 8, 2025 12:56
require Logger

# in this struct, nil means indeterminate
# In this struct
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can define struct fields as atoms, e.g. :selected_installation_type which is a shorter equivalent. Not that you should, just saying.

Comment thread lib/plausible/installation_support/verification/diagnostics.ex
expected_domain = "example.com"
url_to_verify = "https://#{expected_domain}"

diagnostics =
Copy link
Copy Markdown
Member

@aerosol aerosol Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah so you went with tests against pure structs. Is there a integration test confirming that this set of field values is possible to achieve?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! There's not. You'd be right to point out that this creates false confidence. I tried to manage that by having the rest of the struct randomised , to make sure that exactly these fields determine the result, but reverted it (ccd3d73, why: #5693 (comment)).

Now that I think about, it wouldn't be hard to refactor all these cases to live-view tests, where the verifier request output is mocked... I think we should do that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not as high as live view itself though, but the function doing verification that the LV calls perhaps?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea by @aerosol! Perhaps along with other refactoring changes we've talked about, @apata? We could follow the example of LegacyVerification.ChecksTest

@apata apata force-pushed the script-v2/find-script-tag branch from 089035b to c60f4b0 Compare September 10, 2025 09:40
expected_domain = "example.com"
url_to_verify = "https://#{expected_domain}"

diagnostics =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea by @aerosol! Perhaps along with other refactoring changes we've talked about, @apata? We could follow the example of LegacyVerification.ChecksTest

Routes.site_path(socket, :verification, socket.assigns.site.domain,
flow: socket.assigns.flow
flow: socket.assigns.flow,
installation_type: config.installation_type
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing wrong with passing the query param, but since the tracker_script_config object gets updated here we can also read the installation_type from that object during the mount phase of the Verification LiveView.

Why? That would fix it for the case where the customer is redirected directly into the verification screen (e.g. from stats_controller.ex) and we don't know the installation method yet.

cookiesConsentResult,
error: testPlausibleFunctionError
} = await testPlausibleFunction({
isTrackerInHtml: () => isInHtml(trackerScriptSelector),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about checking this directly in this function without polling, after await testPlausibleFunction is finished? Doesn't have to be in this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I hadn't even considered that, updated in eda2186.

@apata apata force-pushed the script-v2/find-script-tag branch from 168bcf1 to 727f13d Compare September 10, 2025 12:55
@apata apata added this pull request to the merge queue Sep 11, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 11, 2025
@apata apata added this pull request to the merge queue Sep 11, 2025
Merged via the queue into master with commit f7acb06 Sep 11, 2025
21 checks passed
@apata apata deleted the script-v2/find-script-tag branch February 11, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants