Replacing the Default Preview Option in Umbraco 18

I have followed the Additional Preview Environments Support article, and my preview feature is working successfully. The issue I’m running into is that the default preview functionality is still running, and throws an error when the preview displays. My IUrlProvider implementation is setup correctly, and I am using the correct alias in my manifest, which consists of the following:

{
name: "Custom URL Preview Option",
alias: "Custom.Extensions.CustomUrl.PreviewOption",
type: "workspaceActionMenuItem",
kind: "previewOption",
forWorkspaceActions: "Umb.WorkspaceAction.Document.SaveAndPreview",
weight: 101,
meta: {
icon: "icon-umbraco",
label: "#customUrl_saveAndPreviewLabel",
urlProviderAlias: "customUrlProvider",
}
}

I receive the JavaScript error in the console of:

[UmbTryExecuteController] Error in request: UmbApiError: Failed to produce a preview URL for the requested document.

There is a request by client.get.ts that sends back a 400 Bad Request. The URL it attempts to access is:

https://localhost:64164/umbraco/management/api/v1/document/b63b10d9-c28f-4c84-90d5-2627dde076aa/preview-url?providerAlias=umbDocumentUrlProvider

As you can see, the umbDocumentUrlProvider (the default) is still trying to load a preview. In my Composer, I have the following:

builder.UrlProviders()
.Clear()
.Append<CustomUrlProvider>();

I’ve also tried:

builder.AddUrlProvider<CustomUrlProvider>();

This also does not prevent the default provider from running.

I’m wondering if anyone else has had this issue, and how to overcome it. I know I could tell my users to ignore the error, since the preview is still working, but someone is eventually going to give me pushback on the error being displayed (or blame the error is something fails on the website).

Thank you for any advice or help, I appreciate it.

Error display:

We hit the same thing. The fix is in the manifest, not in the URL provider registration. Your previewOption is added alongside the built-in one, so the built-in one (umbDocumentUrlProvider) still runs and throws the 400. Tell your option to replace the default with overwrites:

{
  "type": "workspaceActionMenuItem",
  "kind": "previewOption",
  "alias": "Custom.Extensions.CustomUrl.PreviewOption",
  "name": "Custom URL Preview Option",
  "forWorkspaceActions": "Umb.WorkspaceAction.Document.SaveAndPreview",
  "overwrites": "Umb.Document.WorkspaceActionMenuItem.SaveAndPreview",
  "weight": 100,
  "meta": {
    "icon": "icon-eye",
    "label": "#buttons_saveAndPreview",
    "urlProviderAlias": "customUrlProvider"
  }
}

You can leave the default URL provider registered. Just keep builder.AddUrlProvider<CustomUrlProvider>().

If you use Umbraco Workflow: its in-workflow preview button only respects overwrites since Workflow 17.4.0 / 18.1.0, so update if you’re on an older version.

I want to thank you so much for your help in solving this! Just in case anyone else comes across this, clearing all UrlProviders, and appending my custom Url Provider actually continued to show the error. Using the code:

builder.AddUrlProvider<CustomUrlProvider>();

fixed this issue and removed the error. I also no longer have a “drop-up” on Save and Preview to select the default, which makes the interface cleaner and one less thing my users need to understand.