如何从浏览器停止我的JavaScript调试



如何停止从浏览器调试我的js代码

function ViewSeatInfo(busNo, scheduleId, seatFare, tripType, dDate, time, numberOfSeat, seatUpdate, seatId) {
  totalPrice = 0;
  schedule_Id = scheduleId;
  bus_No = busNo;
  trip_Type = tripType;
  d_date = dDate;
  _time = time;
  mainSeatId = seatId;
  window.numberOfSeat = numberOfSeat;
  window.seatUpdate = seatUpdate;
  currentSell = 0;
  var seats = "";
  var data;
  $.ajax({
    type: 'post',
    contentType: 'application/json; charset=utf-8',
    url: "SellTicketOnline.aspx/ShowBusAndSeatInfo",
    data: "{'busNo':'" + busNo + "'," + "'scheduleId':'" + scheduleId + "'}",
    async: false,
    success: function(response) {
      data = response;
    },
    error: function() {
      alert("error");
    }
  });
  seatFare = data.d.BusMainFare;
  seat_Fare = seatFare;
  baseFare = seatFare;
  ShowBusSeatAllocation(data, seatFare);
  LoadStationByRouteId();
  LoadBoardingPoint();
}
网页

的JavaScript在浏览器(客户端)中运行,这意味着浏览器需要下载文件并执行,因此它必须有权访问"原始"JS文件。因此,您无法真正阻止其他开发人员查看您的代码。

您可以做的是使人们更难理解和调试您的应用程序。

一些可用的可能性是:

  • 各种代码混淆技术。
  • 使用 web-socket 或类似方法隐藏代码。
  • 通过覆盖调试器工具(如console.log())来禁用它们,例如:

(function() {
  // disables the use of `console.log`, `console.info`, `console.error`, `console.warn` and others by replacing them with empty functions,
  // this makes the use of the debugger harder.
  var empty = function() {};
  Object.keys(window.console).forEach(function(prop) {
window.console[prop] = empty;
  });
  console.log('log');
  console.info('info');
  console.error('error');
  console.warn('warn');
})(window);

一些有趣的项目和文章:

https://github.com/javascript-obfuscator/javascript-obfuscator

http://www.jsfuck.com/

如何防止你的JavaScript代码被窃取,复制和查看?

最新更新