Skip to content

PageTitle does not modify document.title inside BlazorWebView #61010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
ivanjx opened this issue Mar 19, 2025 · 2 comments
Closed
1 task done

PageTitle does not modify document.title inside BlazorWebView #61010

ivanjx opened this issue Mar 19, 2025 · 2 comments
Labels
area-blazor Includes: Blazor, Razor Components investigate

Comments

@ivanjx
Copy link

ivanjx commented Mar 19, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

i am trying to sync between my blazor app's PageTitle and the window's title but apparently PageTitle is ignored when running inside BlazorWebView control on winforms and maui.

Expected Behavior

PageTitle is set properly so i can read it with document.title with JS interop.

Steps To Reproduce

  1. create a hybrid app.
  2. create a new page and a nav to it.
  3. put <PageTitle>something</PageTitle> in the new page.
  4. run the app and navigate to the new page.
  5. open the built in dev tools (F12).
  6. on the console tab and run document.title.
  7. the result is not something.

Exceptions (if any)

No response

.NET Version

9.0.200

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Mar 19, 2025
@ivanjx ivanjx changed the title PageTitle does not modify title inside BlazorWebView PageTitle does not modify document.title inside BlazorWebView Mar 19, 2025
@javiercn javiercn added this to the .NET 10 Planning milestone Mar 19, 2025
@bradford-fisher
Copy link

bradford-fisher commented Apr 23, 2025

Have you added a RootComponent to the BlazorWebView component targeting head::after? The following is, admittedly, WPF and not MAUI, but might be similar enough to help.

<Window 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:blazor="clr-namespace:Microsoft.AspNetCore.Components.WebView.Wpf;assembly=Microsoft.AspNetCore.Components.WebView.Wpf"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Demo"
    xmlns:web="clr-namespace:Microsoft.AspNetCore.Components.Web;assembly=Microsoft.AspNetCore.Components.Web"
    x:Class="Demo.MainWindow"
    mc:Ignorable="d"
    Title="MainWindow"
    Height="450"
    Width="800"
>
    <blazor:BlazorWebView HostPage="wwwroot/index.html" StartPath="/" Services="{DynamicResource services}">
        <blazor:BlazorWebView.RootComponents>
            <blazor:RootComponent Selector="#application" ComponentType="{x:Type local:AppRouter}"/>
            <blazor:RootComponent Selector="head::after" ComponentType="{x:Type web:HeadOutlet}"/>
        </blazor:BlazorWebView.RootComponents>
    </blazor:BlazorWebView>
</Window>

When I open the developer tools I can see the title element set in the head as specified by the currently loaded PageTitle component.

@ivanjx
Copy link
Author

ivanjx commented Apr 23, 2025

@bradford-fisher thank you for the suggestion. it works now even with winforms.

        blazorWebView1.HostPage = "wwwroot\\index.html";
        blazorWebView1.Services = _sp;
        blazorWebView1.RootComponents.Add<MyApp>("#app");
        blazorWebView1.RootComponents.Add<HeadOutlet>("head::after");

@ivanjx ivanjx closed this as completed Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components investigate
Projects
None yet
Development

No branches or pull requests

3 participants