简体   繁体   中英

window.URL.createObjectURL(blob); is undefined in my application

I'm facing this issue only in my application irrespective of browser (IE & Chrome). If I check window.URL.createObjectURL(blob) in console of any other page in both the browsers, its working fine. But it window.URL.createObjectURL(blob) is getting undefined only in the tab in which I open my application :(

I'm not sure, which library is removing "createObjectURL" method.

following are my scripts

<script src="src/js/libs/jquery/dist/jquery.js"></script>
<script src="src/js/libs/toastr/toastr.js"></script>
<script src="src/js/libs/moment/moment.js"></script>
<script src="src/js/libs/bootstrap/dist/js/bootstrap.js"></script>
<script src="src/js/libs/angular/angular.js"></script>
<script src="src/js/libs/angular-route/angular-route.js"></script>
<script src="src/js/libs/angular-sanitize/angular-sanitize.js></script>
<script src="src/js/libs/angular-animate/angular-animate.js"></script>
<script src="src/js/libs/angular-mocks/angular-mocks.js"></script>
<script src="src/js/libs/angular-bootstrap/ui-bootstrap-tpls.js"></script>

I'm not able to figure out how to get window.URL.createObjectURL

Here is the error in IE console

Error: [IGL] Object doesn't support property or method 'createObjectURL' TypeError: Object doesn't support property or method 'createObjectURL'

Here is the error in Chrome

Error: [IGL] window.URL.createObjectURL is not a function TypeError: window.URL.createObjectURL is not a function

Thanks in advance

I figure out the solution for this by using following script from Arun & @Phil comments. Thanks to both of them.

Its not with any library, in my application somewhere in unused code, there a global URL object which is overriding the window.URL.

I found this by using the following code:

(function () {
        var _createObjectURL = window.URL.createObjectURL;
                Object.defineProperty(window.URL, 'createObjectURL', {
                set: function (value) {
                console.trace('set createObjectURL')
                        _createObjectURL = value;
                },
                        get: function () {
                        console.trace('get createObjectURL')
                                return _createObjectURL;
                        }
                })
                })();
                (function () {
                var _URL = window.URL;
                        Object.defineProperty(window, 'URL', {
                        set: function (value) {
                        console.trace('set URL')
                                _URL = value;
                        },
                                get: function () {
                                console.trace('get URL')
                                        return _URL;
                                }
                        })
                        })();  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM