XmlHttpRequest open() is implicitly sync in Revit 2022.1 CefSharp because of journal overrides
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In a Revit addin that I'm working on I'm using the Revit CefSharp instance to display a Web UI. In this Web UI I'm using the Angular HttpClient to send the HTTP requests. After upgrading Revit 2022 to Revit 2022.1 the following error occurred: 'Failed to set the 'responseType' property on 'XMLHttpRequest' The response type cannot be changed for synchronous requests made from a document'
The Angular HTTPClient uses the XMLHttpRequest to send a request to the server. I am able to reproduce the error in a simple add-in which loads a browser instance with the following testscript:
function run() {
const xhr = new XMLHttpRequest();
xhr.open("GET", "/api/GetApiTest");
xhr.responseType = "json";
}
In Revit 2022.1 it crashes on the line: xhr.responseType = "json";.
The issue seems to be caused by an addition to the CefSharp of Revit 2022.1 in which a script related to the Journal is injected. This script file overrides the `open()` method on the XMLHttpRequest, does some logging and calls the original `open()` method:
// call original open()
XMLHttpRequest_open.call(this, method, url, async, user, password);
This approach works fine when another script uses the overload with all parameters: 'open(method: string, url: string | URL, async: boolean, username?: string | null, password?: string | null): void;'
In the case of the Angular HTTP client the simplified overload: 'open(method: string, url: string | URL)' is being used, so recalling with the full overload implicitly sets the async parameter to false causing the error.
It looks like this is a bug in the injected journal scripts, as the correct overload will never be called. In my test script the issue can be solved by explicitly setting the async parameter to true. But I don't have the opportunity to explicitly set the async parameter to true in the Angular HttpClient. So I will need to override the XMLHttpRequest.open in my scripts to add the async true parameter and recall the original method.
I'm wondering if anyone else has encountered this issue before and if there any plans to fix this in upcoming Revit versions.
Developer Advocacy and Support +