Editor’s Note: This article was updated December 2019 lớn be more up-to-date.

Bạn đang xem: How to fix script error when accessing quickbooks desktop?

“Script error” is one of the most cryptic error messages you may encounter. The main grievance is it provides no information about the actual cause of the problem. However, this secrecy is not a bug, but a feature that intends khổng lồ protect your site from malicious attacks.

Please refer lớn the aryannations88.com technical documentation regarding Script errors for quick fixes khổng lồ the most common causes.


What are Script errors?

Script errors occur when a client-side script that violates the same-origin policy of the user’s browser by making an invalid cross-origin HTTP request.

If you’re working on a website and have aryannations88.com Crash Reporting hooked into your client-side JavaScript, “Script error” will probably be one of the first things you will notice appearing in your dashboard.

Quick Links

What causes Script errors?

Script errors are mostly likely khổng lồ be caused by an error within a script that’s hosted on a different domain name (for example, CDN scripts). As a result, the user’s browser stops the script from executing in order lớn prevent an attack called cross-site request forgery. However, it may also be a problem if the script is stored on the same domain name but uses a different port, protocol (for example http:// instead of https://), or subdomain.

For example, an error within a script on another domain name might look like this:
// File: https://another-domain.com/index.jsconst a = ;console.log(a.b.c);

In your domain, calling that script may look like this. This scenario will yield a script error being sent lớn aryannations88.com4JS.
// File: origin-domain.com/index.htmlscript src="http://another-domain.com/index.js">/script>

What is a Long Running Script?

You may also find an error similar to Script error in your aryannations88.com dashboard, called “Long Running Script”. Their names are similar, but they are entirely different errors you need lớn handle differently.

While Script error is caused by violating the browser’s same-origin policy, a Long Running Script indicates performance issues. Every browser has a timeframe for script execution. If a script needs more time to lớn execute, a Long Running Script error will occur. The user will also be presented with a dialog box where they can decide if they want to lớn stop the script or keep waiting for their asset to lớn load.

You can resolve the Long Running Script error by using coding best practices, modularizing your scripts, và thoroughly testing code before deployment under as many different conditions as possible.

Script error–The same-origin policy

CORS, or Cross-Origin Resource Sharing, is an official W3C recommendation that defines the mechanism of properly making cross-origin requests on the client side. The same-origin policy, enforced by modern browsers, means that scripts only have full access rights if they are loaded from the same origin domain name as the original document—when the script passes the CORS validation.

With regards to the architecture of modern websites và applications, CORS & the same-origin policy present a problem. Due khổng lồ the nature of HTTP 1.1, key resources (including JavaScript) are hosted on non-origin, or ‘third-party’, domains. Particular to lớn this problem, CDNs use the massive resources of public clouds lớn keep both costs và response times low.

When your website application code is defined & loaded to a script hosted on a different tên miền to the one in the address bar, errors that hit the window.onerror sự kiện handler won’t have any stack trace or message context for you to lớn debug.

Not having a stack trace isn’t a problem when developing locally. However, no information on an error becomes a critical issue when trying lớn figure out why a site is breaking on a user’s machine. This is most obvious when aryannations88.com4JS reports these errors, & the error groups lack any indication as lớn what happened.

Control the same-origin policy

The specification và implementation for controlling the same-origin policy is documented nicely here. You’ll notice proper implementations are only available in modern browsers. See different browser behaviors in detail at the kết thúc of the article.

There are two critical pieces of metadata to lớn include lớn allow a cross-domain script to pass the CORS validation in a modern browser. You need lớn use the first one on the script tag you địa chỉ cửa hàng to the HTML on the origin domain & the second one on the HTTP response sent by the third-party domain.

1. On the origin domain

As the above documentation lists, you need khổng lồ use the crossorigin attribute on the appropriate script tag. By example:


// File: origin-domain.com/index.htmlscript crossorigin="anonymous" src="https://another-domain.com/index.js">/script>
Omitting the protocol from the URL when including the script will result in the current protocol being used when fetching the script. This can be useful in a development environment where https:// is not used.
Without the crossorigin attribute present, browsers don’t use CORS at all, meaning they assume that the requested script is hosted on the same origin and can load without security risks. However, when they recognize that the script is requested from a third-party domain, your browser will refuse to lớn load it.

When you địa chỉ cửa hàng the crossorigin attribute with the anonymous keyword, you notify the user’s browser that you want to use the CORS mechanism to perform a secure cross-site request. Thus, there is no exchange of user credentials via cookies or HTTP authentication when the request is sent back và forth.

2. On the third-party domain

The second critical bit of data is the presence of an HTTP header on the response from the third-party domain name containing the JavaScript. In particular, the Access-Control-Allow-Origin header:


The wildcard in this example allows cross-site requests khổng lồ any site. This is appropriate for a CDN where the script may be requested by any third-party domain. If this is a private host for a known phối of domains, you can provide that các mục in place of the wildcard, for instance:


You need to lớn implement the Access-Control-Allow-Origin response header on the third-party hệ thống where the external script is coming from. How & where to showroom the HTTP header depends on the type of the third-party server.

For example, here is a code example you can use on an Apache server. You can địa chỉ cửa hàng it to the .htaccess file. It enables the third-party server to send all files using the .js extension lớn any external domain.


Or, if you don’t only want to showroom CORS tư vấn for scripts but other resources you may need, such as website fonts and CSS you can use the following code instead:


For instance, here’s what I get in Chrome 66, without the third-party hệ thống sending the proper HTTP header:

*
As you can see, the browser can’t load the external script, và an error message appears in the console.

After adding CORS tư vấn to the server, the Access-Control-Allow-Origin header appears in the response, the third-party script loads correctly, và the error message disappears from the console:

*

If you want to địa chỉ CORS tư vấn to a different vps platform, there’s a great trang web called Enable CORS you may find helpful. It shares code examples & implementations for several different platforms such as IIS, Nginx, Tomcat, và others. Besides, larger CDN providers such as KeyCDN also frequently have tư vấn pages that explain how you can phối custom HTTP headers on their platform.

Use a website proxy

Using a web proxy is an alternative method you can use khổng lồ get around the problem. It can be especially useful if, for some reason, you can’t modify the HTTP header sent by the third-party server. You need to set up a proxy on your website server, then make your Ajax requests, not lớn the third-party domain, but to lớn the web proxy hosted on the same domain.

The proxy hệ thống forwards the request khổng lồ the third-party server, fetches the script, và sends it back lớn your website. Thus, the browser interprets it as a same-origin request and allows your frontend code to access the third-party script. The website proxy, in fact, functions as an intermediary for your requests from other servers.

There are some open-source CORS proxies available on the web, such as crossorigin.me or CORS Anywhere. However, these services should be only used in development. Never use an xuất hiện CORS proxy on a production site, they are unreliable và may pose serious security risks.

Different browser behaviors regarding Script error

Depending on what browser your users are running, the above properties may or may not have an effect. This sums up the situation as of writing, regarding browser tư vấn for the crossorigin attribute và CORS:

Chrome 30+Firefox 13+Opera 12.50+Safari (at least 6+)Edge 0.10+

In these browsers, if the script tag is present, the HTTP header needs to lớn be also present. Otherwise, the script will be blocked.

Firefox has an additional behaviour for Runtime Errors. These will be provided to window.onerror, regardless of the two properties. These aren’t a security risk. Syntax errors, however, will be blocked in both Gecko và WebKit browsers, if the crossorigin attribute is present, but the associated cross-origin domain lacks the header.

Xem thêm: Thế Nào Là Cặp Alen Là Gì ? Alen Nghĩa Là Gì Thế Nào Là Cặp Alen

Internet Explorer aryannations88.com Crash Reporting surfaces your Script errors for you. See what the buzz is about & start your không tính phí 14-day trial.