Claude: Rate limit screenshots if identical
This commit is contained in:
parent
4d1da05a87
commit
ff48bf931c
@ -25,6 +25,7 @@
|
|||||||
var blockCache = null;
|
var blockCache = null;
|
||||||
var processCount = 0;
|
var processCount = 0;
|
||||||
var curVT = 0;
|
var curVT = 0;
|
||||||
|
var lastScreenshot = null;
|
||||||
function writeData(buf, vt)
|
function writeData(buf, vt)
|
||||||
{
|
{
|
||||||
if(vt != 1)
|
if(vt != 1)
|
||||||
@ -395,16 +396,34 @@
|
|||||||
switch(tool.action)
|
switch(tool.action)
|
||||||
{
|
{
|
||||||
case "screenshot":
|
case "screenshot":
|
||||||
|
{
|
||||||
|
var delayCount = 0;
|
||||||
|
while(1)
|
||||||
{
|
{
|
||||||
// TODO: Resize
|
// TODO: Resize
|
||||||
var display = document.getElementById("display");
|
var display = document.getElementById("display");
|
||||||
var dataUrl = display.toDataURL("image/png");
|
var dataUrl = display.toDataURL("image/png");
|
||||||
|
if(dataUrl == lastScreenshot)
|
||||||
|
{
|
||||||
|
// Delay at most 3 times
|
||||||
|
if(delayCount < 3)
|
||||||
|
{
|
||||||
|
// TODO: Defensive check, validate and remove
|
||||||
|
debugger;
|
||||||
|
delayCount++;
|
||||||
|
// Wait some time and retry
|
||||||
|
await new Promise(function(f, r) { setTimeout(f, 5000); });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastScreenshot = dataUrl;
|
||||||
// Remove prefix from the encoded data
|
// Remove prefix from the encoded data
|
||||||
dataUrl = dataUrl.substring("data:image/png;base64,".length);
|
dataUrl = dataUrl.substring("data:image/png;base64,".length);
|
||||||
var imageSrc = { type: "base64", media_type: "image/png", data: dataUrl };
|
var imageSrc = { type: "base64", media_type: "image/png", data: dataUrl };
|
||||||
var contentObj = { type: "image", source: imageSrc };
|
var contentObj = { type: "image", source: imageSrc };
|
||||||
return [ contentObj ];
|
return [ contentObj ];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case "mouse_move":
|
case "mouse_move":
|
||||||
{
|
{
|
||||||
var coords = tool.coordinate;
|
var coords = tool.coordinate;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user