debuggerWorker.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. "use strict";
  2. /**
  3. * Copyright (c) Facebook, Inc. and its affiliates.
  4. *
  5. * This source code is licensed under the MIT license found in the
  6. * LICENSE file in the root directory of this source tree.
  7. *
  8. */
  9. /* global __fbBatchedBridge, self, importScripts, postMessage, onmessage: true */
  10. /* eslint no-unused-vars: 0 */
  11. onmessage = function () {
  12. var visibilityState;
  13. var showVisibilityWarning = function () {
  14. var hasWarned = false;
  15. return function () {
  16. // Wait until `YellowBox` gets initialized before displaying the warning.
  17. if (hasWarned || console.warn.toString().includes('[native code]')) {
  18. return;
  19. }
  20. hasWarned = true;
  21. console.warn('Remote debugger is in a background tab which may cause apps to ' + 'perform slowly. Fix this by foregrounding the tab (or opening it in ' + 'a separate window).');
  22. };
  23. }();
  24. var messageHandlers = {
  25. executeApplicationScript: function (message, sendReply) {
  26. for (var key in message.inject) {
  27. self[key] = JSON.parse(message.inject[key]);
  28. }
  29. var error;
  30. try {
  31. importScripts(message.url);
  32. } catch (err) {
  33. error = err.message;
  34. }
  35. sendReply(null
  36. /* result */
  37. , error);
  38. },
  39. setDebuggerVisibility: function (message) {
  40. visibilityState = message.visibilityState;
  41. }
  42. };
  43. return function (message) {
  44. if (visibilityState === 'hidden') {
  45. showVisibilityWarning();
  46. }
  47. var object = message.data;
  48. var sendReply = function (result, error) {
  49. postMessage({
  50. replyID: object.id,
  51. result: result,
  52. error: error
  53. });
  54. };
  55. var handler = messageHandlers[object.method];
  56. if (handler) {
  57. // Special cased handlers
  58. handler(object, sendReply);
  59. } else {
  60. // Other methods get called on the bridge
  61. var returnValue = [[], [], [], 0];
  62. var error;
  63. try {
  64. if (typeof __fbBatchedBridge === 'object') {
  65. returnValue = __fbBatchedBridge[object.method].apply(null, object.arguments);
  66. } else {
  67. error = 'Failed to call function, __fbBatchedBridge is undefined';
  68. }
  69. } catch (err) {
  70. error = err.message;
  71. } finally {
  72. sendReply(JSON.stringify(returnValue), error);
  73. }
  74. }
  75. };
  76. }();
  77. //# sourceMappingURL=debuggerWorker.js.map