Set MIME type for ".mjs" file loaded in WebView of vscode extension - visual-studio-code

I am working on a vscode extension that displays a webpage inside a WebView.
The webpage has a <script> tag with type="module" and is sourced through vscode-resource protocol. That JS module fails to load inside WebView with the following error:
"Failed to load module script: The server responded with a non-JavaScript MIME type of "application/unknown". Strict MIME type checking is enforced for module scripts per HTML spec."
How can I set the MIME type for that resource?

You need to set the server to send .mjs files as JavaScript MIME type
text/javascript

Related

Cannot load webUI correctly

I could get the page on localhost:8089 but not the style.css .These are the results from firefox and chrome:
Firefox:
GET http://localhost:8089/static/style.css?v=1.0 [HTTP/1.1 200 OK 17ms]
The stylesheet http://localhost:8089/static/style.css?v=1.0 was not loaded because its MIME type, “application/x-css”, is not “text/css”.
Chrome:
localhost/:5 Resource interpreted as Stylesheet but transferred with MIME type application/x-css: "http://localhost:8089/static/style.css?v=1.0".
How to make the web normal? pls help.
Is it possible you are encountering the same problem mentioned here?
https://community.grafana.com/t/grafana-start-but-stylesheets-not-displayed/3250/11
Specifically check your registry (https://gogs.io/docs/intro/troubleshooting#windows):
Error: Resource interpreted as Stylesheet but transferred with MIME type application/x-css
Causes: wrong value in the Windows registry
Solution: Find .css in HKEY_CLASSES_ROOT in registry and change its Content Type to text/css.

TYPO3 v9.5.0 - Error message: Requested page does not exist /robots.txt

TYPO3 v9.5.0 - Error message: Requested page does not exist /robots.txt
I have a TYPO3 9.5.0LTS and use the bootstrap package theme. It seems to be all working ... but quite often I get such error messages:
Core: Exception handler (WEB): Uncaught TYPO3 Exception: #1518472189: The requested page does not exist | TYPO3\CMS\Core\Error\Http\PageNotFoundException thrown in file /is/www/typo3_src-9.5.0/typo3/sysext/frontend/Classes/Controller/ErrorController.php in line 82. Requested URL: domain/robots.txt
What causes this and how to prevent this? Or how do I create a robots.txt in v.9.5 ?
In TYPO3 9.5 you can add a robots.txt in your Sites module.
Sites -> Choose your site -> Static Routes -> Create new.
Static Route Name: select "robots.txt"
Route Type: select "Static Text"
Static Text: Select "robots.txt Example Content"
Save. Should be fixed now.
This will work for all TYPO3 versions. For TYPO3 V9.x use the solution by Thomas Löffler.
Your server configuration (apache? .htaccess?) will hand over any request to a source that is no file and no directory and no symbolic link to the index.php file which is TYPO3.
In your case, you do not have a file robots.txt. So TYPO3 wants to handle it, but has no resource with that name. This creates a 404 error in TYPO3.
To prevent this, jst create the robots.txt file on your webserver in the DOCUMENT_ROOT folder
So what is a robots.txt file anyway.
This is a method to tell search engines how to behave on your server. It contains recomendations to the search engines' crawlers, when to stop crawling (like typo3_src folder). It is requested by the crawlers automatically and regularly.

Integrate With Google button: Failed to execute ‘postMessage’ on ‘DOMWindow’

I am trying to add Integrate With Google button to our website using the instructions at https://developers.google.com/gsuite/marketplace/button.
According to the instruction, I need to add:
<script type="text/javascript" src="https://apis.google.com/js/platform.js"/>
to head and then incorporate:
<g:additnow applicationid="[appid]"></g:additnow>
The button is not rendered. The error in browser console says:
Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘https://accounts.google.com’) does not match the recipient window’s origin (‘http://server.local:8090’).
Load denied by X-Frame-Options: `
https://apis.google.com/additnow/additnow.html?usegapi=1&applicationid=[appid]&origin=http%3A%2F%2Fserver.local%3A8090&gsrc=3p&ic=1&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en_US.Vch8vd-lM6E.O%2Fm%3D__features__%2Fam%3DAQE%2Frt%3Dj%2Fd%3D1%2Frs%3DAGLTcCOgsbyjgLVijKgLfaXMbki4Pxbd_A#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh%2Claunchurl&id=I0_1517552817258&_gfid=I0_1517552817258&parent=http%3A%2F%2Fserver.local%3A8090&pfname=&rpctoken=19038946
> does not permit cross-origin framing.
A couple of points:
I am loading the page using the Tomcat web server
server.local resolves to 127.0.0.1
http anywhere browser extension is disabled
The page is not being loaded in an iframe
I tried loading platform.js without https. make no difference.
Any ideas?

GWT : separate js + css + images from server

We'd like to have the following configuration :
one server is replying to GWT RPC : x.com (the one running Java)
another server is serving js / css / images : y.com (for bandwith optimization)
So the main page is : http://x.com/index.html
and contains this line: <script type="text/javascript" language="javascript" src="http://**x.com**/my-app.nocache.js"></script>
We're getting a SOP error: Unsafe JavaScript attempt to access frame with URL ...
Any suggestion, help about that ?
Add the following to your gwt.xml:
<add-linker name="xsiframe" />
This will generate slightly different code, that can be loaded cross-origin. Your "host page" will still have to be loaded from the same server you run your GWT-RPC servlets on, to not hit the SOP.
See this FAQ entry (the "xs" linker predates the "xsiframe" one, that latter is now preferred, and could eventually even replace the "std", default linker)
You have hit Same Origin Policy which prevents making XMLHTTPRequest to servers other than origin server. This effectively prevents cross-domain GWT-RPC.
The possible workarounds are described in Making cross-site requests:
Run a proxy on your server
Load the JSON response into a <script> tag

Downloading file by WebClient Exception

I have a problem downloading particular file types by WebClient. So there are no problems with usual types - mp3, doc and others, but when I rename file extension to config it returns me:
InnerException = {System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
when I'm trying to access this file in browser (http://localhost:3182/Silverlight.config) - it's a usual xml file within - server returns me following error page:
Server Error in '/' Application.
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.config' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /Silverlight.config
So I suppose this hapens because of some server configuration, which blocks files of unknown type.
downloading code is simple:
WebClient webClient = new WebClient();
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
webClient.OpenReadAsync(new Uri("../Silverlight.config", UriKind.RelativeOrAbsolute));
completted eventhandler omitted for simplicity.
I'm not sure this is possible.
The .config extension is handled by the ASP.NET engine, for security reasons (sensitive data like connection strings need to be kept safe and hidden from unauthorized viewers).
This means that visitors cannot view your web.config file's content by simply entering "www.example.com/web.config" into their browser's adress bar.
EDIT : actually you can but I don't recommand it. If you really need to do it, you have to remove the mapping between the .config extension and ASP.NET ISAPI filter in IIS.