console - What’s the quickest, easiest way to execute a JavaScript file on a live web page? - Stack Overflow

I have this JavaScript file URL:.min.js(hosted on GitHub and passed through RawGit), and I would like t

I have this JavaScript file URL:

.min.js

(hosted on GitHub and passed through RawGit), and I would like to inject it into a live web page via the browser’s console.

In order to achieve that, I can dynamically create a <script> element and append it to the DOM:

(function () {
  var s = document.createElement('script');
  s.src = '.min.js';
  document.body.appendChild(s);
}())

But this is neither quick nor easy. I would like to use an API that makes this possible via a simple invocation, e.g.:

exec('.min.js')

Do Chrome or Firefox provide such an API (or anything similar) in their console?


Use case: Quickly testing JavaScript libraries hosted on GitHub on live web pages.

I have this JavaScript file URL:

https://rawgit./Khan/tota11y/master/build/tota11y.min.js

(hosted on GitHub and passed through RawGit), and I would like to inject it into a live web page via the browser’s console.

In order to achieve that, I can dynamically create a <script> element and append it to the DOM:

(function () {
  var s = document.createElement('script');
  s.src = 'https://rawgit./Khan/tota11y/master/build/tota11y.min.js';
  document.body.appendChild(s);
}())

But this is neither quick nor easy. I would like to use an API that makes this possible via a simple invocation, e.g.:

exec('https://rawgit./Khan/tota11y/master/build/tota11y.min.js')

Do Chrome or Firefox provide such an API (or anything similar) in their console?


Use case: Quickly testing JavaScript libraries hosted on GitHub on live web pages.

Share Improve this question asked Jun 10, 2015 at 20:07 Šime VidasŠime Vidas 186k65 gold badges289 silver badges391 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 9

Update: The Developer Toolbar has been removed from Firefox Nightly as of 18th May 2018.

In Firefox, you can inject scripts using the Developer Toolbar. Bring it up withShift+F2 and type inject https://rawgit./Khan/tota11y/master/build/tota11y.min.js

More info on MDN

You need a module loading capability from what I see. You have two routes:

  • Either use a module loader like Require.js that already does that kind of dynamic loading for you. It enforces you to use AMD style of scripts though. This website talks a bit more about modules in javascript. The require object will be available in console since it is global.

  • Use a hackish function that does that like jQuery does here, if you use jQuery already (it is a pretty big library to import just for this). jQuery is global and you can call that function in console.

EDIT: The reason I did not link browser specific functionality is because it is too specific. Using a JavaScript only solution works across all browsers to test for patibility.

For chrome there's a plugin called Script Injector that does exactly that

https://chrome.google./webstore/detail/script-injector/fddnddnolonllcgfbenaloajnbhebmob?hl=en

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745159767a4614336.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信