Web Component: Dom Exception: This name has already been used - javascript

tl:dr; I don't know how to fix the error below on the site here:
You will need credentials:
un: stackoverflowuserj23jf4#mailinator.com
pass: testingStackOverflow123
Details: I am trying to conditionally include a web component in a page like so:
<script>
document.addEventListener("DOMContentLoaded", function(event) {
if (document.querySelector('simple-fred')) {
var script = document.createElement('script');
script.src = 'https://embedint.crossroads.net/fred/js/simplefred.min.js';
document.head.appendChild(script)
}
});
</script>
Including the script conditionally instead of statically broke the code. The script above used to be loaded like this:
<script src="https://embedint.crossroads.net/fred/js/simplefred.min.js"></script>, which worked
I then include the element on the page:
<simple-fred data-form-name="buildingblocksformarriage" data-redirect-url="/care/weddings/building-blocks-for-marriage/signup/confirmation"> </simple-fred>
This works fine locally and on plunker.
To run it on plnkr, you do need to disable CORS blocking for Chrome, the command is:
TASKKILL /F /IM chrome.exe
start chrome.exe --args --disable-web-security --user-data-dir
pause
This is all good and well, but when I run this code in concert with other code, it fails. I get the following error (same error, browsers report it differently):
Chrome:
Uncaught DOMException: Failed to execute 'define' on
'CustomElementRegistry': this name has already been used with this
registry
at Function.value (https://embedint.crossroads.net/fred/js/simplefred.min.js:5:383105)
Mozilla:
Error: A custom element with name 'slim-repeat' has already been
defined.
This error seems to be caused by two third-parties trying to create the same custom component as far as I can tell judging by this question I have a bounty on
I am at a loss at this point. The int environment that throws the error is here:
https://int.crossroads.net/care/weddings/building-blocks-for-marriage/signup
You may need a login, I made one so it's faster (can be shared):
stackoverflowuserj23jf4#mailinator.com
testingStackOverflow123
The code is open source and is found here (I don't think looking at it will help, just for completeness): https://github.com/crdschurch/crds-fred/blob/development/CrdsFred/Views/Form/Index.cshtml
How do I fix this?
Or at least, what are possible causes? I will throw at least a 100 point bounty on this to reward the accepted answer.

it looks like there's a node module named slim-js, and it creates an element called slim-repeat on lines 1057 and/or 1146 of Slim.js (see screenshot). Maybe you just need to pick a different name?

I am the author of this library and would like to assist. I will deploy a hot fix for this Issue. Eventually not running the whole script if another instance of Slim is already initialized.

Related

Cypress.io: Server Error | 404 - File or director not found

I'm currently trying to automate the test for a pretty big webapplication (DMS) Document Management System. To explain the system a little bit: There is a loadbalancer which connect to one of two frontends. To be sure that will be no problems in my test I directly try to access frontend one. Now to my problem:
When trying to run all the tests (around 20 spec-Files) with the Test Runner and also when trying to run the tests via console with the following command: .\node_modules\.bin\cypress run --spec "cypress/integration/Basis/**/*" --browser chrome
Sometimes after a cy.visit() a Server Error comes up. That error also stops the tests on console from running and looks like it crashes cypress. The error is the following:
It's not possible that the resource is missing or somewhere else because most of the times the test works. Most of the time its a different test where the error comes up. The worst part is that I have no idea how to reproduce that error. And it looks like that problem is only appearing for me.
So please tell me if you have ever seen this message and maybe you can help me fix this problem. Thank you for your help.
This is caused by a bug in Cypress which causes usages of window.location.href and other Location methods to incorrectly use /__/ as the base URL.
You can try enabling the experimentalSourceRewriting config option to work around this, read here for more info: https://docs.cypress.io/guides/references/experiments.html#Configuration

Error message "DevTools failed to load SourceMap: Could not load content for chrome-extension://..."

I'm trying to display an image selected from the local machine and I need the location of that image for a JavaScript function. But I'm unable to get the location.
To get the image location, I tried using console.log, but nothing returns.
console.log(document.getElementById("uploadPreview"));
Here's the HTML code:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div align="center" style="padding-top: 50px">
<img align="center" id="uploadPreview" style="width: 100px; height: 100px;" />
</div>
<div align="center" style="padding-left: 30px">
<input id="uploadImage" type="file" name="myPhoto" onchange="PreviewImage();" />
</div>
<script type="text/javascript">
function PreviewImage() {
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("uploadImage").files[0]);
oFReader.onload = function (oFREvent) {
document.getElementById("uploadPreview").src = oFREvent.target.result;
console.log(document.getElementById("uploadPreview").src);
};
}
</script>
</body>
</html>
Console Output:
Here's the warning:
DevTools failed to load SourceMap: Could not load content for
chrome-extension://alplpnakfeabeiebipdmaenpmbgknjce/include.preload.js.map:
HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
That's because Chrome added support for source maps.
Go to the developer tools (F12 in the browser), then select the three dots in the upper right corner, and go to Settings.
Then, look for Sources, and disable the options:
"Enable JavaScript source maps"
"Enable CSS source maps"
If you do that, that would get rid of the warnings. It has nothing to do with your code. Check the developer tools in other pages and you will see the same warning.
Go to Developer tools → Settings → Console → tick "Selected context only". The warnings will be hidden. You can see them again by unticking the same box.
The "Selected context only" means only the top, iframe, worker and extension contexts. Which is all that you'll need, the vast majority of the time.
Fixing "SourceMap" error messages in the Development Tools Console caused by Chrome extensions:
Examples caused by McAfee extensions:
DevTools failed to load SourceMap: Could not load content for chrome-extension://klekeajafkkpokaofllcadenjdckhinm/sourceMap/content.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
DevTools failed to load SourceMap: Could not load content for chrome-extension://fheoggkfdfchfphceeifdbepaooicaho/sourceMap/chrome/content.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
DevTools failed to load SourceMap: Could not load content for chrome-extension://fheoggkfdfchfphceeifdbepaooicaho/sourceMap/chrome/iframe_handler.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
If you are developing, then you need "Enable JavaScript source maps" and "Enable CSS source maps" checked to be able see your source code in Chrome Developer Tools. Unchecking those takes away your ability to debug your source code. It is like turning off the fire alarm instead of putting out the fire. You do not want to do that.
Instead you want to find the extensions that are causing the messages and turn them off. Here is how you do that:
Go to the three dots in the upper right hand corner of Chrome.
Go to "More Tools" and click on "Extensions".
Do this for one extension at a time until no more "SourceMap" errors are in the console:
Turn off the extension by sliding the switch to the left.
Reload the page that you were using the Development Tools on.
Check if any of the "SourceMap" error messages disappeared.
If any did, then that extension was causing those messages.
Otherwise, that extension can be turned back on.
After determining which extensions caused the issue either:
If you need it, then contact the maker to have them fix the issue.
Otherwise, remove the extension.
I stumbled upon this Stack Overflow question after discovering loads of source map errors in the console for the Edge browser. (I think I had disabled the warnings in the Chrome browser long ago.)
For me it meant first realising what a source map is; please refer to Macro Mazzon's answer to understand this. Since it's a good idea, it was just a case of finding out how to turn them on.
It's as simple as adding this line in your webpack.config.js file -
module.exports = {
devtool: "source-map",
}
Now that Edge could detect a source map, the errors disappeared.
Apologies if this answer insults anybody's intelligence, but maybe somebody reading this will be as clueless about source maps as I was.
The include.prepload.js file will have a line like below, probably as the last line:
//# sourceMappingURL=include.prepload.js.map
Delete it and the error will go away.
For me, the problem was caused not by the application in development itself, but by the Chrome extension React Developer Tool. I solved it partially by right-clicking the extension icon in the toolbar, clicking "Manage extension" and then enabling "Allow access to files URLs." But this measure fixed just some of the alerts.
I found issues in the React repository that suggests the cause is a bug in their extension and is planned to be corrected soon - see issues 20091 and 20075.
You can confirm is extension-related by accessing your application in an anonymous tab without any extension enabled.
Chrome has changed the UI in 2022, so this is a new version of the most upvoted reply.
Open the dev tools (hit F12 or Option + Command + J)
Select the gear at the top. There are two gears in that area, so be sure to select the one at the top, top.
Locate the Sources section
Deselect "Enable JavaScript source maps"
Check to see if it worked!
Right: it has nothing to do with your code. I've found two valid solutions to this warning (not just disabling it). To better understand what a source map is, I suggest you check out this answer, where it explains how it's something that helps you debug:
The .map files are for JavaScript and CSS (and now TypeScript too) files that have been minified. They are called SourceMaps. When you minify a file, like the angular.js file, it takes thousands of lines of pretty code and turns it into only a few lines of ugly code. Hopefully, when you are shipping your code to production, you are using the minified code instead of the full, unminified version. When your app is in production, and has an error, the sourcemap will help take your ugly file, and will allow you to see the original version of the code. If you didn't have the sourcemap, then any error would seem cryptic at best.
First solution: apparently, Mr Heelis was the closest one: you should add the .map file and there are some tools that help you with this problem (Grunt, Gulp and Google closure for example, quoting the answer). Otherwise you can download the .map file from official sites like Bootstrap, jQuery, font-awesome, preload and so on... (maybe installing things like popper or swiper by the npm command in a random folder and copying just the .map file in your JavaScript/CSS destination folder)
Second solution (the one I used): add the source files using a CDN (content delivery network). (Here are all the advantages of using a CDN). Using content delivery network (CDN) you can simply add the CDN link, instead of the path to your folder. You can find CNDs on official websites (Bootstrap, jquery, popper, etc.) or you can easily search on some websites like Cloudflare, cdnjs, etc.
Extensions without enough permissions on Chrome can cause these warnings, for example for React developer tools. Check if the following procedure solves your problem:
Right click on the extension icon.
Or
Go to extensions.
Click the three-dot in the row of React developer tool.
Then choose "This can read and write site data".
You should see three options in the list. Pick one that is strict enough based on how much you trust the extension and also satisfies the extension's needs.
I appreciate this is part of your extensions, but I see this message in all sorts of places these days, and I hate it: how I fixed it (this fix seems to massively speed up the browser too) was by adding a dead file
physically create the file it wants it/where it wants it, as a blank file (for example, "popper.min.js.map")
put this in the blank file
{
"version": 1,
"mappings": "",
"sources": [],
"names": [],
"file": "popper.min.js"
}
make sure that "file": "*******" in the content of the blank file matches the name of your file ******.map (minus the word ".map")
(I suspect you could physically add this dead file method to the addon yourself.)
I do not think the warnings you have received are related. I had the same warnings which turned out to be the Chrome extension React Dev Tools. I removed the extension and the errors were gone.
You have just missing files.
Go to the website https://www.cdnpkg.com/.
Download what you need and copy it to the right folder.
For me, the warnings were caused by the Selenium IDE Chrome extension. These warnings appeared in the Console on every page load:
DevTools failed to load source map: Could not load content for chrome-extension://mooikfkahbdckldjjndioackbalphokd/assets/atoms.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
DevTools failed to load source map: Could not load content for chrome-extension://mooikfkahbdckldjjndioackbalphokd/assets/polyfills.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
DevTools failed to load source map: Could not load content for chrome-extension://mooikfkahbdckldjjndioackbalphokd/assets/escape.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
DevTools failed to load source map: Could not load content for chrome-extension://mooikfkahbdckldjjndioackbalphokd/assets/playback.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
DevTools failed to load source map: Could not load content for chrome-extension://mooikfkahbdckldjjndioackbalphokd/assets/record.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
Since Selenium IDE was already set to be able to read site data on all sites, I uninstalled it. (I read in another comment here that you might try enabling more permissions for an extension instead of removing it.) In my case, removing Selenium IDE (Chrome extension) got rid of the warnings.
It is also possible to add the file that is missing, aside with other .js libraries in the same folder (no need to reference the .map in the .html file, <script> tag).
I had the same error, when trying to code in Backbone.js.
The problematic file was backbone-min.js, and the line that created the error was sourceMappingURL=backbone-min.map.
After downloading the missing file (the link comes from here), the error disappeared.
I had the same problem. I tried to disable the extensions one by one to check it, and finally realized I had Adblock enabled, which was causing this issue. To remove that error I followed the step below,
Three dots (top right corner).
Click More tools --> extensions.
Disable the Adblock.
Reload the page.
And it should work now.
DevTools failed to load source map: Could not load content for chrome-extension://cfhdojbkjhnklbpkdaibdccddilifddb/browser-polyfill.js.map: System error: net::ERR_FILE_NOT_FOUND
Disable the Chrome extension "Adblock Plus - free ad blocker". https://chrome.google.com/webstore/detail/adblock-plus-free-ad-bloc/cfhdojbkjhnklbpkdaibdccddilifddb
Lately this error is caused by the extension.
Problems with Debugging and Sourcemaps in Web Browsers
Hope this clarifies the technicals behind the problem...knowing how things works helps some :)
This browser error means it has some compiled version of your JavaScript in a sourcemap intermediate file it or some 3rd party created that is now needed when debugging that same script in "devtools" in your web browser.
This can happen if your script fails (or in your case trying to get an image source hidden in the sourcemap code that created the script) but whose script error is tied to some JavaScript that got created from an original sourcemap file that now cannot be found to debug that same error. So it's an error about an error, a missing debugging file creating a new error. (crazy, huh?)
This error is likely coming from an extension in the web browser and is reporting it has generated a script error it has recorded in the console.log window of devtools (press F12 in the browser). The error is likely from the extension (not your code) saying it has some code that contains an address to a sourcemap file it cannot access, has a bad URI/URL address, is blocked, or that is missing.
The browser only needs this sourcemap file if a developer using devtools will need to debug the original script again.
A sourcemap, by the way, is a file that translates or transpiles code from one language to another language. Often this is a file that the browser uses to translate this source code into a child script like JavaScript/ECMAScript, or when it needs to do the opposite and recreate the source file from the child script. In most cases this file is not needed at all as a 3rd party software program has already compiled or transpiled the source code into the child script for the browser. For example, developers who like TypeScript use it to create JavaScript. This source code gets transpiled into JavaScript so the browser script engine can run it. The URI/URL to this sourcemap file is usually at the top of the javaScript or application compiled code file in a format like //#....
When this intermediary transpile file is missing or blocked for security reasons in a web browser, the application will usually not care unless it needs the source file for debugging the child script using this source file. In that case it will complain when it feels it needs this file and cannot find it, as it uses it to recreate the source file for the code running in the browser when debugging the script in order to allow a developer to debug the original source code. When it cannot find it, it means that any developer trying to debug it will not be able to do so, and is stuck with the compiled code only. So it is safe to turn off these errors in the various ways mentioned in this post. It should not affect your own scripts if it is connected to an extension. Even if it is related to your own scripts, it is still unlikely you need it unless you plan to run debugging from devtools.
In my case, it was JSON Viewer extension that was blocking the source map files from being loaded
In my case i made silly mistake by adding bootstrap.min.js instead of bootstrap.bundel.js :)
You need to open Chrome in developer mode: select More tools, then Extensions and select Developer mode

GET net::ERR_FAILED error when probing for extension

There is a certain Chrome extension and I want to get a PNG file from it by XMLHttpRequest. If the extension is enabled, I want to write 'load' to the console, and if the extension is disabled, I want to write 'error' to the console.
It works fine, but if the Extension is disabled, Chrome writes an error in the console that I do not want to appear:
How can I remove this error from the console?
(I have tried window.onerror but it doesn't work)
The code:
var loadHref = function(href) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function(){console.log('load')};
xmlhttp.onerror = function() {console.log('error');};
xmlhttp.open('GET', href);
xmlhttp.send();
}
loadHref('chrome-extension://77672b238520494cba8855547dd00ba8/img/icon24.png');
Basically, you can't silence those errors, as they are not JS errors but network errors.
Assuming your goal is to detect that a specific extension is present:
Assume you need it at a specific domain and for a specific extension that is controlled by you.
In this case, the optimal approach is externally_connectable communication. Here's a sample.
Assume you need it at a non-specific domain not known in advance, but you control the extension.
In this case, a Content Script can be injected (probably with "run_at": "document_start") and add something to the document signalling the presence of the extension. For example, injecting a page-level script that sets a variable.
Assume you don't control the extension.
Well, in that case you're screwed. If an extension won't cooperate in the manners described above, probing its web-accessible resources (if any!) is the only way to detect it, short of watching for specific content script activity in the DOM (again, if any).
Actually, there is already an existing issue on error when chrome cast extension is not installed with google-cast-sdk and based on that issues tracker, this hasn't been totally resolved yet. There are, however, given workarounds from one of the comments:
the workarounds would be to either install the Google Cast extension or disable network warnings (please note you may miss some warnings that could be on interest to you) so you don't see these additional logs.
And, you may also try with the probable solutions given in this SO post - Google chrome cast sender error if chrome cast extension is not installed or using incognito and who knows, it might help. :)

Javascript "Object Required" Error

I'm working at an organization that only uses IE 8 (Windows 7). Every user gets a policy that includes a predefined set of settings. I have a problem with a javascript code only occurring on 2 machines (these two machines are from the same department).
The line of code is:
if (mgr[k] == SystemUser().substr(1, SystemUser.length))
The error I get is "Object Required". I've also written a code to display a message of each value and found that the error is regarding the function SystemUser().
I need an idea to what might cause this error to show on those 2 machines. Is there a definition in the internet options that will block this function? Do I need to install something for it to be supported?
I'm inserting the SystemUser() code
function SystemUser(){
WShShell = new ActiveXObject("WScript.Network");
return WshShell.UserName;
}
Thanks to the comments, I realized that the problem was in accessing the function SystemUser(). The function was written in an external js file. Both users, using these machines, did not have permissions to read the js file.
Granting them read permission to the external script solved the problem.

Crm 2011 with no javascript customizations gives onload errors

we are getting the following error in almost all create or edit entity forms. the systems is not customized at all and it works perfectly:
There was an error in the fields customized event.
field:window
event:onload
error:object doesn't support this property or method
after debugging the error I found out that it is happening in FormScript.js.aspx page in the following code block:
var eContext=Mscrm.FormUtility.constructExecutionObject(eventObj,0,null,null);
eContext=Mscrm.FormUtility.constructExecutionObject(eventObj,0,null,eContext)
Mscrm.Form_onload();
Mscrm.Form_onload() is what causing the error to happen.
do you have any idea why is this happening?
It was a server side problem. I don't know exactly why it happens. we also tried to do an installation repair but that didn't solve it. Finally, we installed a fresh CRM 2011 copy on a new server, imported the database and ran Data migration manager. and the error disappeared.
Are you absolutely positive there is no script attached to run on load of any of the entities that are having issues? That particular function should just run any custom script you have on the entity, so I don't see any other cause.
Odd, there is certainly some garbage in there somewhere
function crmForm_window_onload_handler(eventObj,eventArgs){
try{
var eContext=Mscrm.FormUtility.constructExecutionObject(eventObj,0,null,null);
eContext=Mscrm.FormUtility.constructExecutionObject(eventObj,0,null,eContext)
loadInsideView();
eContext=Mscrm.FormUtility.constructExecutionObject(eventObj,1,null,eContext)
CEI.Initialize();
} catch(e) {
displayError('window', 'onload', e.description);
}
}
Here is one from our system on the account form. I have no idea how this could have happened, but I would check the events for the page (not just the onload). I would also try adding a JavaScript web resource with a generic event to the onload to see if by toggling it on, the system might clean itself up. You may have to call Microsoft or find the issue in your 4.0 and fix it to do another re-install. I feel for you on this one!

Categories

Resources