tom
tom

Reputation: 91

No results in Browser with "Getting Started with the Closure Library"

I am following the given steps to try, "Getting Started with the Closure Library".

https://developers.google.com/closure/library/docs/gettingstarted

Step 1: Download and Setup the Closure Library Step 2: Create a JavaScript file that uses the Closure Library Step 3: Create an HTML file Step 4: Say Hello (with the created file) to the Closure Library.

Yet when using Chrome as the browser, on a PC, these steps yield a blank screen.

Is there some restriction with the example in Chrome? The example was saved on C: Drive, in a directory for the closure-library, C:\hw3_1\closure-library. Note here, this is not a homework problem, yet a trial of the closure-library.

Right-clicking the screen, the following code is displayed:

Sample Suggested Code for Google Closure

As a test, when clicking on the hypertext, "closure-library/closure/goog/base.js" the file opens in the browser. Likewise, clicking on the hypertext for "hello.js", this file also opens in the browser.

The example simply yields a blank screen. Is there a solution available?

Upvotes: 1

Views: 132

Answers (1)

Dave
Dave

Reputation: 883

The problem was when I ran hello.js I got blank Chrome output (the same as the Original Poster) But I was fortunate enough to check the browser debug.

Access to XMLHttpRequest at blah blah closure-library/closure/goog/debug/error.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.

If anyone else gets this look in Chrome>More Tools>Developer Tools>Console you will see the above type message alongside your "blank screen". See this link for details: Cross-Origin Resource Sharing (CORS)

The solution is to launch a single Chrome session using the following in Command Window (Run as Admin)

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir=~/repos

Of course these are my settings. Use Win Explorer to find your own chrome.exe and copy "Address as text" to a Notepad page. Assemble the remaining instruction - stating the folder where your .js & .html "Getting Started with the Closure Library" files are.

Paste the completed instruction string into the Command window. This should immediately launch a new Chrome session.

When the Chrome window launches it will have a gentle warning. Just type in your path & filename into the URL space.

Mine was file:///C:/Users/david/source/repos/hello.html

From here you can see the text Hello world! contained within the sayHi() function of hello.js showing in the HTML output.

This will let you move on with Google Developer Getting Started with the Closure Library

Upvotes: 0

Related Questions