如何在.aspx网页上进行异步内容更新后,如何保留chrome中的用户标题修改

发布于 2025-01-25 11:45:56 字数 2928 浏览 1 评论 0 原文

我正在尝试为我公司的库存系统自动化网页的工作流程。该页面由ASP.NET页面的服务器端逻辑生成,我无法访问该页面。该页面上有几个字段,可让您输入新的容器条形码,应该在容器中进行的项目等。这些字段中的每个字段都有一个 onChange 事件侦听器挂在它上页面的 __ dopostback()函数以验证输入的数据。如果验证了数据,则将页面代码重新安装,并在到目前为止输入数据,并将焦点设置为表单上的下一个字段。

我想用Chrome中的Userscript自动化此页面。我首先使用fivermonkey注入自定义脚本,但是我只能在初始加载的情况下,而不是在每个数据输入之后触发脚本。之后,我尝试使用Chrome Local覆盖来更改 __ dopostback()尝试捕获自动化页面所需的数据。那也只能工作一次;填充字段并失去焦点并提供新的HTML后,它覆盖了Chrome的本地副本。

我认为我的问题是由整个页面内容的异步刷新引起的,该内容删除了注入的用户标题和Chrome的本地覆盖,而无需触发普通页面刷新chrome in Chrome或collemonkey的刷新听众以重新注射修改后的代码。是否有人对如何以在页面内容被新的HTML替换后可以持续存在的方式来修改JavaScript有任何想法?

PS我认为代码本身与此特定问题无关,但是如果有人认为分享客户端代码的有限部分会很有帮助,请告诉我。

编辑1 :这是我要完成的工作以及到目前为止取得的进步的更深入的观点。作为参考,该表格看起来像这样:

我的原始计划

  1. 用户加载页面。 LiberMonKey注入了一个发行一系列提示的用户标记,收集了用户希望输入系统的新条形码范围的数据。 (具体来说,条形码前缀,启动条形码号和结尾条形码。)此值存储在 localStorage 中。

  2. 在收集并验证了这些数据后,页面正常加载。作为参考,该表格看起来像这样:

  1. ​填写每个字段(除了容器描述字段之外)之后,页面将焦点推向下一个字段。 (例如:< script Lakenanage =“ javascript”> try {document.getElementById('txtContDesc')。focus()} catch(e){}</script> 。通过服务器逻辑动态更改焦点的字段。)

  2. 我需要收集用户徽章,容器类型和目标条形码值,以便在自动化表单自动化时以后可以对其进行补充。我最初的计划是将 onfocus 事件侦听器添加到容器描述字段中,因为一旦验证了目标条形码字段,焦点将转移到它。我将知道这一点,用户已成功输入了容器描述字段上方的每个字段的有效条目,然后我将能够收集这些值并将其存储在 localStorage 。<<<<<>。 /p>

  3. 一旦我拥有该表单所需的所有数据,我将使用fivermonkey中的userscript和存储在 localStorage 中的数据进行驾驶表单,以在页面刷新中持久数据。

其他替代方案:

eventListener 元素上的想法不起作用,因为ASP.NET每次验证字段都会使用新的代码更新页面,从而删除听众。它也不会触发刷新,因此《暴力蒙基》不会重新运行我的用户字样。

我的另一个想法是修改 dopostback() dopostback()函数看起来像这样(据我所知):

<script type="text/javascript">
   var theForm = document.forms['formNewContainer'];
      if (!theForm) {
         theForm = document.formNewContainer;
      }
      function __doPostBack(eventTarget, eventArgument) {
          console.log("Form submitted");
      }
</script>

在经过验证的字段上调用了以下 onChange handler:

onchange="javascript:setTimeout('__doPostBack(\'ctl00$newContPage$txtBarcode\',\'\')', 0)"

我的目标是修改<代码> dopostback()要保存我需要 localstorage 的信息,然后再执行 dopostback()而无需更改 dopostback()。

(注意: dopostback()在这里看起来非常简单,因此我认为我缺少有关ASP.NET在这里工作的一些信息。但是,这超出了问题,除非它与我的内容相关我尝试做。)

我能够使用Chrome Local覆盖来成功修改 dopostback(),以便我自己为页面加载的页面本地副本提供服务,而不是服务器版本。但这仅适用于第一个 dopostback()请求。在第一个请求之后,服务器为我服务了新的代码。与暴力蒙基一样,缺乏刷新触发器可以防止Chrome本地覆盖重新发送我的本地副本,并且我在没有 dopostback()修改的情况下提供了代码。

这就是我所在的地方。我将尝试添加像@woxxom建议的那样的全局听众,看看那是我的何处。

I'm trying to automate the workflow of a webpage for my company's inventory system. The page is generated by the server-side logic of an ASP.Net page, which I don't have access to. The page has several fields on it to allow you to enter a new container barcode, the item that should go in the container, etc. Each of these fields has an onchange event listener hooked up to it which calls the page's __doPostBack() function to verify the entered data. If the data is verified, the page code is re-served with the data entered so far, and focus is set to the next field on the form.

I want to automate this page with a userscript in Chrome. I started by using ViolentMonkey to inject a custom script, but I could only get the script to trigger on the initial load, not after each data entry. After this, I tried using Chrome Local Overrides to change __doPostBack() to try to capture the data I need to automate the page. That also only works once; after a field is filled and loses focus and new HTML is served, it overwrites Chrome's local copy.

I think that my problems are being caused by an asynchronous refresh of the entire page contents, which wipes out the injected userscript and Chrome's Local Override without triggering the normal page refresh listeners in Chrome Overrides or ViolentMonkey to re-inject the modified code. Does anyone have any thoughts on how I could modify the JavaScript in such a way that it would persist after the page content is replaced with new HTML?

P.S. I don't think the code itself is relevant to this particular problem, but if anyone thinks it would be helpful to share a limited section of the client-side code, let me know.

Edit 1: Here's a more in-depth view of what I'm trying to accomplish, and the progress I've made so far. For reference, the form looks like this:

My Original Plan

  1. The user loads the page. ViolentMonkey injects a userscript which issues a series of prompts, collecting data on the range of new barcodes that the user would like entered into the system. (Specifically, the barcode prefix, the starting barcode number, and the ending barcode number.) This values are stored in localStorage.

  2. After this data has been collected and validated by the user, the page loads normally. For reference, the form looks something like this:

sample.png

  1. The user fills out the fields as normal. After each field is filled out (with the exception of the Container Description field), the page pushes focus to the next field. (For example: <script language="javascript"> try { document.getElementById('txtContDesc').focus() } catch (e) { } </script>. The id of the field to focus is dynamically changed via the server logic.)

  2. I need to collect the User Badge, Container Type, and Destination Barcode values so that I can refill them later when I automate the form. My original plan was to add a onfocus event listener to the Container Description field, since focus will be shifted to it once the Destination Barcode field has been verified. I will know at this point that the user has successfully entered a valid entry for each of the fields above the Container Description field, and I would then be able to collect these values and store them in localStorage.

  3. Once I have all the data needed for the form, I would pilot the form using the userscript in ViolentMonkey and the data stored in localStorage, to persist data across page refreshes.

Other Alternatives:

The eventListener idea on an element doesn't work, because ASP.NET updates the page with fresh code every time a field is verified, wiping out the listener. It also doesn't trigger a refresh, so ViolentMonkey doesn't rerun my userscript.

My other thought was to modify doPostBack(). The doPostBack() function looks like this (as far as I can tell):

<script type="text/javascript">
   var theForm = document.forms['formNewContainer'];
      if (!theForm) {
         theForm = document.formNewContainer;
      }
      function __doPostBack(eventTarget, eventArgument) {
          console.log("Form submitted");
      }
</script>

It is called on verified fields with the following onchange handler:

onchange="javascript:setTimeout('__doPostBack(\'ctl00$newContPage$txtBarcode\',\'\')', 0)"

My goal would be to modify doPostBack() to save the information I need to localStorage before executing the rest of doPostBack() without changing it.

(Note: doPostBack() here looks incredibly simplistic, so I think I'm missing some information about how ASP.NET works here. This is outside of the question though, unless it's relevant for what I'm trying to do.)

I was able to successfully modify doPostBack() in this way using Chrome Local Overrides to serve myself a local copy of the page on page load, instead of the server version. But this only works for the first doPostBack() request. After the first request, the server serves me new code. Like with ViolentMonkey, the lack of a refresh trigger prevents Chrome Local Overrides from re-serving my local copy, and I'm served code without the doPostBack() modification.

So that's where I'm at. I'll try adding a global listener like @wOxxOm suggested, and see where that gets me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不再见 2025-02-01 11:45:56

我最终使用了称为“运行JavaScript”的镀铬扩展名(具有徽标的大象),即使在Ajax请求上也可以运行JavaScript代码。

链接:

I ended up using a Chrome extension called "Run Javascript" (has an elephant for it's logo), which runs the JavaScript code even on AJAX requests.

Link: https://chrome.google.com/webstore/detail/run-javascript/lmilalhkkdhfieeienjbiicclobibjao/

傲鸠 2025-02-01 11:45:56

我看不出这是怎么可能的。您需要与创建该网页的人一起工作。

ASP.NET和服务器端代码将是广泛的.NET代码(C#或VB.NET)。您触发的每个事件都会为要运行的代码设置变量和服务器端会话(或ViewState)值。

这就是ASP.NET页面的工作方式。您发布后退,页面传递到服务器,然后在运行后面的.NET代码。该代码将修改页面,修改控件并修改该页面的视图状态。并且在该代码运行之后(例如,单击按钮),您的客户端将收到一个全新的新鲜页面 - 它将吹出您尝试和注射的任何JavaScript。 (您每次都必须重新注射)。但是,情况变得更糟,因为在检查后面的大量代码也很糟糕,并且通常不容容忍页面设置已被弄乱,并且会被拒绝。

这样做的唯一方法是编写一些桌面软件,该软件将“容纳”或“主机”网页的完整“ com”对象副本,因此您可以自动化该给定的页面。 (即使那样,您仍在与一场失败的战斗中进行战斗)。

暗示:
Web开发,业务逻辑和功能性业务应用并不是一些简单的标记和JavaScript(尽管la脚2周,HTML课程告诉您了什么)。

这是一个应用程序,是ASP.NET应用。试图将其视为一些标记和JavaScript实际上在这里非常愚蠢。这不是您为公司编写或建立业务解决方案的方式。

如果您无法编写和修改代码和Web服务器端,请找出该站点是否具有某种Web API或其他内容。

但是,确实 - 这很愚蠢,除非这是一些简单的大学项目,或者有些被黑客入侵的HTML页面和一些JavaScript?忘记这种方法 - 您处理服务器上的服务器端太多和代码。

实际上,如所指出值,数据库主键值和整个状态值的船值可能100%保存在服务器端session()基于类的对象中 - 以及永远不会暴露服务器端的对象。

进行假设的修改或假设您只能使用客户端工具来创建或修改该系统无法正常工作 - 只是行不通。

在运行后面的代码后,它使用.NET代码重新处理页面,然后将整个页面寄回 - 所有页面都带有新状态值等。这不是某些lake html html + javaScript,而是编写的完整服务器端代码驱动的系统C#.NET代码。

I don't see how this is possible at all. You need to work with the people that created that web page.

Asp.net and the server side code will be EXTENSIVE .net code (c# or vb.net). Each of those events you trigger will set variables and server side session (or viewstate) values for the code behind to run.

That's how asp.net pages work. You post back, page travels up to server, THEN the .net code behind runs. That code will modify the page, modify controls, and modify the view state for that page. And after that code runs (say on a button click), then you client side will receive a whole new fresh page - that will blow out any JavaScript you try and inject. (you would have to re-inject each time). But, it gets worse, since quite of bit of that code behind also checks and often will NOT tolerate that the page settings have been messed with, and will be rejected.

About the only way to do this would be to write some desktop software, and that software would "house" or "host" a full "com" object copy of the web page, and you thus automate that given page. (and even then, you still fighting a losing battle).

Hint:
Web development, business logic, and a functional business applcation is NOT some simple markup and JavaScript (despite what that lame 2 week HTML course tells you).

This is a application, and asp.net applcation. Trying to think of this as just some markup and JavaScript is actually quite silly here. It not how you write, or build business solutions for a company.

If you can't write and modify the code and the web server side of things then find out if that site has some kind of web api or whatever.

But, really - this is silly, and unless this is some simple college project, or some hacked up html page and some JavaScript? Forget this approach - you dealing with FAR too much server side and code behind on the server.

In fact, asp.net as noted has quite a bit built in features that check if the page being posted back been messed with, and you never really be sure that you set values and that the proper amounts of code behind that runs to setup row values, database primary key values and a WHOLE boatload of state values that are probably 100% saved in server side session() based class objects - and objects that are never exposed server side.

Tring to supposed modify or assume you can create or modify such a system with only client side tools is not going to work - its just not.

code behind runs, it re-processes the page with .net code and then sends the whole page back down - all with new state values etc. This is not some lame html + JavaScript, but is a full server side code driven system written in c# .net code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文