aspnet / BrowserLink

Browser Link loader for Visual Studio integration
Apache License 2.0
17 stars 21 forks source link

Browser Link produces JavaScript error in browser console #104

Closed scottaddie closed 4 years ago

scottaddie commented 4 years ago

I've tested with both VS 2019 Enterprise 16.4.2 and VS 2019 Enterprise 16.5.0 Preview 1.0. Browser Link isn't working for me in either version.

Steps to reproduce:

  1. In VS 2019, go to File -> New -> Project

  2. Create an ASP.NET Core 3.1 Razor Pages app named WebApplication1

  3. Add the following package refs to the project file:

    <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.0" Condition="'$(Configuration)' == 'Debug'" />
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
  4. Replace the contents of Startup.cs with the following code:

    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    
    namespace WebApplication1
    {
        public class Startup
        {
            public Startup(IConfiguration configuration, IWebHostEnvironment env)
            {
                Configuration = configuration;
                Env = env;
            }
    
            public IConfiguration Configuration { get; }
            public IWebHostEnvironment Env { get; }
    
            public void ConfigureServices(IServiceCollection services)
            {
                var builder = services.AddRazorPages();
    
    #if DEBUG
                if (Env.IsDevelopment())
                {
                    builder.AddRazorRuntimeCompilation();
                }
    #endif
            }
    
            public void Configure(IApplicationBuilder app)
            {
                if (Env.IsDevelopment())
                {
                    app.UseBrowserLink();
                    app.UseDeveloperExceptionPage();
                }
                else
                {
                    app.UseExceptionHandler("/Error");
                    app.UseHsts();
                }
    
                app.UseHttpsRedirection();
                app.UseStaticFiles();
                app.UseRouting();
                app.UseAuthorization();
                app.UseEndpoints(endpoints => endpoints.MapRazorPages());
            }
        }
    }
  5. Open the Browser Link Dashboard window, click Enable Browser Link, and click View in Browser.

  6. Open the browser developer tools (Chrome in this case) and view the Console tab. Notice the following error message:

    image

jodavis commented 4 years ago

There is a bug in Visual Studio 16.5 Preview 1 that causes this error. It has been fixed for Preview 2.

It shouldn't affect 16.4, though. Did you still have the project open in 16.5 when you tested that? If the same project is opened in two instances of VS, the browser has to choose one of them to connect to, and it's usually the one that was opened first.

scottaddie commented 4 years ago

@jodavis I did still have the project open in 16.5. I've confirmed that everything works as expected if I only have the project open in 16.4.

jodavis commented 4 years ago

Good to hear it's working in 16.4. The bug in 16.5 is fixed in Preview 2, which will be released soon. I recommend checking here for updates: https://developercommunity.visualstudio.com/content/problem/850188/browserlink-not-working-in-1650-preview-10.html