我试图显示从本地机器选择的图像,我需要该图像的位置用于JavaScript函数。但我查不到地址。

为了获得图像位置,我尝试使用console.log,但没有返回任何结果。

console.log(document.getElementById("uploadPreview"));

下面是HTML代码:

<!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>

控制台输出:

以下是警告:

DevTools无法加载SourceMap:无法加载内容 chrome扩展:/ / alplpnakfeabeiebipdmaenpmbgknjce / include.preload.js.map: HTTP错误:状态代码404,net::ERR_UNKNOWN_URL_SCHEME


这是因为Chrome增加了对源地图的支持。

转到开发人员工具(浏览器中的F12),然后选择右上角的三个圆点,然后转到设置。

然后,查找Sources,并禁用这些选项:

“启用JavaScript源映射” “启用CSS源映射”

如果你这么做,警告就会消失。这与你的代码无关。检查其他页面中的开发人员工具,您将看到相同的警告。


我很欣赏这是你的扩展的一部分,但我看到这条消息在各种各样的地方这些天,我讨厌它:我如何修复它(这个修复似乎大大加快了浏览器)是通过添加一个死文件

物理上创建它想要的文件/在它想要的位置,作为一个空白文件(例如,"popper.min.js.map") 把这个放进空白文件里 { “版本”:1、 “映射”:“”, “来源”:[], “名称”:[], “文件”:“popper.min.js” } 确保空白文件内容中的“file”:“*******”与您的文件名******相匹配。Map(去掉。Map这个词)

(我怀疑你可以自己把这个死文件方法添加到插件中。)


include.prepload.js文件将有如下一行,可能是最后一行:

# sourceMappingURL=include.prepload.js.map

删除它,错误就会消失。


我不认为你收到的警告是相关的。我有同样的警告,原来是Chrome扩展React Dev Tools。我删除了扩展,错误消失了。


在Chrome上没有足够权限的扩展可能会导致这些警告,例如React开发工具。看看下面的步骤是否能解决你的问题:

右键单击扩展图标。

Or

做延伸。 单击React开发人员工具行中的三个点。

然后选择“这可以读写站点数据”。

您应该在列表中看到三个选项。根据您对扩展的信任程度,选择一个足够严格的扩展,同时满足扩展的需求。


对我来说,这个问题不是由开发中的应用程序本身引起的,而是由Chrome扩展React Developer Tool引起的。我通过右键单击工具栏中的扩展图标,单击“管理扩展”,然后启用“允许访问文件url”来部分解决这个问题。但这项措施只修复了部分警报。

我在React存储库中发现了问题,这表明原因是他们的扩展中的一个错误,并计划很快得到纠正-请参阅问题20091和20075。

您可以通过在匿名选项卡中访问应用程序而不启用任何扩展来确认与扩展相关。


你需要在开发者模式下打开Chrome:选择更多工具,然后选择扩展,然后选择开发者模式


正确:这与你的代码无关。对于这个警告,我找到了两个有效的解决方案(不仅仅是禁用它)。为了更好地理解源映射是什么,我建议你看看这个答案,它解释了它是如何帮助你调试的:

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.


进入开发人员工具→设置→控制台→勾选“仅选择上下文”。警告将被隐藏。你可以通过取消同一个方框的勾选来再次看到它们。

“仅选择上下文”仅指顶部、iframe、工作上下文和扩展上下文。在绝大多数情况下,这就是你所需要的。


修复由Chrome扩展引起的开发工具控制台中“SourceMap”错误消息

由McAfee扩展引起的例子:

DevTools failed to load SourceMap: Could not load content for chrome-extension:// klekeajafkkpokaufllcadenjdckhinm / SourceMap /content。map: HTTP错误:状态代码404,net::ERR_UNKNOWN_URL_SCHEME

DevTools failed to load SourceMap: Could not load content for chrome-extension://fheoggkfdfchfphceeifdbepaooicaho/ SourceMap /chrome/content。map: HTTP错误:状态代码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错误:状态代码404,net::ERR_UNKNOWN_URL_SCHEME

如果你正在开发,那么你需要勾选“启用JavaScript源映射”和“启用CSS源映射”,才能在Chrome开发者工具中看到你的源代码。取消选中这些选项会使您无法调试源代码。这就像关掉火警,而不是把火扑灭。你不会想这么做的。

相反,您希望找到引起消息的扩展并将其关闭。你可以这样做:

转到Chrome右上角的三个点。 转到“更多工具”,点击“扩展”。 每次对一个扩展执行此操作,直到控制台中不再出现“SourceMap”错误: 向左滑动开关,关闭分机。 重新加载正在使用开发工具的页面。 检查是否有任何“SourceMap”错误消息消失。 如果有的话,就是这个扩展引起了这些消息。 否则,该扩展可以重新打开。

在确定哪些扩展导致了问题之后:

如果你需要它,然后联系制造商让他们解决这个问题。 否则,删除扩展名。


在Edge浏览器的控制台中发现大量源映射错误后,我偶然发现了这个Stack Overflow问题。(我想我很久以前就禁用了Chrome浏览器中的警告。)

对我来说,这意味着首先意识到源地图是什么;请参考Macro Mazzon的回答来理解这一点。既然这是个好主意,那么问题就在于如何打开它们。

这就像在webpack.config.js文件中添加这一行一样简单

module.exports = {
    devtool: "source-map",
}

现在Edge可以检测到源映射,错误就消失了。

如果这个回答侮辱了任何人的智力,我很抱歉,但也许读到这篇文章的人会像我一样对源地图一无所知。


也可以添加丢失的文件,除了在同一文件夹中的其他.js库(不需要在.html文件中引用.map, <script>标记)。

我有同样的错误,当试图在Backbone.js编码。

有问题的文件是backbone-min.js,而产生错误的行是sourceMappingURL=backbone-min.map。

下载丢失的文件后(链接来自这里),错误消失了。


你只是丢失了文件。

访问https://www.cdnpkg.com/网站。 下载你需要的文件并复制到正确的文件夹。


对我来说,这些警告是由Selenium IDE Chrome扩展引起的。这些警告出现在控制台中每次页面加载:

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

由于Selenium IDE已经设置为能够读取所有站点上的站点数据,所以我卸载了它。(我在这里读到另一个评论,你可以尝试为一个扩展启用更多权限,而不是删除它。)在我的情况下,删除硒IDE (Chrome扩展)摆脱了警告。


Chrome在2022年改变了用户界面,所以这是被点赞最多的新版本回复。

打开开发工具(按F12或选项+命令+ J) 选择顶部的齿轮。那个区域有两个齿轮,所以一定要选择最上面的那个。 定位来源部分 取消选择“启用JavaScript源映射”

检查它是否工作!


Web浏览器中的调试和源地图问题

希望这能澄清问题背后的技术问题…了解事物的运作方式会有所帮助:)

这个浏览器错误意味着它在sourcemap中间文件中有一些你的JavaScript的编译版本,或者是一些第三方创建的,现在需要在你的web浏览器的“devtools”中调试相同的脚本。

如果您的脚本失败(或者在您的情况下,试图获取隐藏在创建脚本的源地图代码中的图像源),但其脚本错误与一些从原始源地图文件创建的JavaScript绑定,现在无法找到用于调试相同错误的JavaScript。这是一个关于错误的错误,一个缺失的调试文件创建了一个新的错误。(疯狂的吧?)

此错误可能来自web浏览器中的扩展,并报告它已经在devtools的console.log窗口中记录了一个脚本错误(在浏览器中按F12)。错误可能来自扩展程序(而不是您的代码),说它有一些代码包含它不能访问的源地图文件的地址,有一个坏的URI/URL地址,被阻止,或丢失。

只有当使用devtools的开发人员需要再次调试原始脚本时,浏览器才需要这个源地图文件。

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.


我也有同样的问题。我试图一个接一个地禁用扩展来检查它,最后意识到我启用了Adblock,这导致了这个问题。为了消除这个错误,我执行下面的步骤,

三个点(右上角)。 单击更多工具—>扩展。 禁用广告拦截。 重新加载页面。

现在应该可以了。


在我的例子中,是JSON Viewer扩展阻止了源地图文件的加载


在我的情况下,我犯了一个愚蠢的错误,添加bootstrap.min.js而不是bootstrap. bundle .js:)


DevTools无法加载source map: Could not load content for chrome-extension://cfhdojbkjhnklbpkdaibdccddilifddb/browser-polyfill.js。map:系统错误:net::ERR_FILE_NOT_FOUND

禁用Chrome扩展“Adblock Plus -免费广告拦截器”。https://chrome.google.com/webstore/detail/adblock-plus-free-ad-bloc/cfhdojbkjhnklbpkdaibdccddilifddb

最近这个错误是由扩展引起的。