I've got a web scraper-ish set of functions that I'm writing in Swift, and I'm using the JavaScriptCore library to... well, execute some JavaScript. I've scraped a file from the web, but it only has a couple of functions that I'm interested in. However, parts of the file contain things like window or window.currentScript, or new window.WeakMap... these things are unfortunately not defined in JavaScriptCore.
This is one of the errors that I'm getting, for example:
TypeError: undefined is not an object (evaluating 'window.document.currentScript.src.indexOf')
Something I'm attempting to do in the meantime is monkeypatch all of the erroring things, like this:
window={};window.document.currentScript.src={};window.document.currentScript.src.indexOf={}
And prepending this to the JS. However, there must be a better way... right?
What I ended up doing was disregarding these references to window altogether—the functions I needed from the JS file didn't ever reference window or its properties. I did some regex magic (magix?) to extract the definitions of the functions I wanted, and made a new string for just those functions. Then, I gave that string to JSContext.evaluateScript. I hope this helps someone!
Related
I have a simple pdf file containing an embedded file (test.xml) I'm trying to add a JS to call it once the pdf file is opened (even with notification to user to accept the risk etc). I've read that to perform that, the JS that should be used is this:
this.ExportDataObject({cName:"test.xml", nLaunch:2});
For some reason, it is not working. I checked the debug js console on my Acrobat reader DC (version 2021.001.20145) the the error shown is TypeError: this.ExportDataObject is not a function. I'm not sure why on my "this" object the ExportDataObject is not available... I think it should be available always, shouldn't it? I also tested without the this. and the error is different ReferenceError: ExportDataObject is not defined.
That makes to think to me that this.ExportDataObject is existing but is not a function as the original error said... but, if is not a function, what is? a typeof is showing "undefined". Not sure how to make this work. Not sure if next steps should more JS debugging or if the problem is related to something on pdfs or Acrobat. Any help? thanks.
Javascript function names are case-sensitive and as documented by Adobe (p. 151), the correct spelling is exportDataObject() without the leading capitalization.
I believe you misspelled ExportDataObject()
It should be exportDataObject()
Using Javascript you should be careful as it is easy to mess up spelling as JS will interpret that in different ways.
As like most of the languages, js is also case sensitive.
But ReferenceError: ExportDataObject is not defined, ReferenceError always states that the object is not defined at all, and could'nt be found among the class methods.
so you need to make sure the function with the exact exportDataObject name is present and use them accordingly.
Im using jQuery-migrate on a big project. I corrected all the warnings I could but now the warnings are inside libraries.
Some libraries are not updated anymore so I can't update them to make them work with jQuery-3.3.1.
Also, I can't replace the depreciated functions directly in the libraires because it is creating errors.
So I think that I'll keep jQuery-migrate in my project.
My question is : If jQuery-migrate is able to correct the depreciated functions when called, why it can not correct them directly in the code ?
JavaScript does not lend itself to static code analysis.
Say you needed to replace the foo function.
That would be fairly trivial if the code that called it was simply:
something.foo();
It becomes rather harder if it is:
function call(bar, method) {
bar[method]();
}
call(something, "foo");
… and even harder if the logic needed to get there was more complicated.
Creating something.foo so it just exists if anything try to access it at runtime is much simpler.
I am new to GWT and trying to create a small application. I am currently assembling a small framework for the app, a generic layout handler, etc. This may not be the last problem I will bump into, but I just cannot find any solution to this on google.
So I have a class type, which return me Composites. Also, I have another one, which stores these kind of classes in Stack (I also tried Vector, I thought maybe GWT has issues with it). It didn't matter. If I call the .clear method on the Stack, I have the aforementioned error in the inspection menu of Chrome:
Uncaught TypeError: Cannot read property 'clear_31_g$' of undefined
Like if GWT does not know, how to convert this method to javascript or what? Do you know what is the problem here?
eclipse neon, Java 7 setting on Java SDK 1.8 (maybe this?), GWT 2.7.0 and App Engine 1.9.34
Thanks!
edit1: I also found the page, which contains the emulated JRE classes' list (http://www.gwtproject.org/doc/latest/RefJreEmulation.html) with all supported methods. Now I see, that clear is not on that list for Stack, but empty does and that gives me the same error. :-/
This error simply means that you try to call the clear() method on a null object (the object is undefined).
The error message itself is not as clear as it could be. First, it's not always about reading a property but also about calling a method. Second, remember that you run a compiled to javascript code and the property (or method) name may differ from the original one - it has something like _31_g$ added in the runtime.
I have an Object in my javascript called file. Running console.log(file) allows me to inspect the object in Firebug like so...
Here is the problem: when I try to access file.status I get 0. file.name and the other attributes all work fine... it is just status that outputs 0 no matter what.
Any ideas what is going on???
BTW, this object is a plupload File object, if that matters. Also, the Webkit Inspector produces the same results.
Thanks!
I suspect it is the security around JavaScript that prevents sharing the details. It is not lying, but not telling you things. Good JavaScript, another citizen protected.
Java security can make it hard to manipulate the files ahead of time as well, thus why there are so many uploader utilities, ok and because of IE7-9 not supporting multi-file browser selection. Example YUI Uploader or SWFUploader.
interesting, if I had this mystery and wanted to get to the bottom of it - I would have either read the code that creates and manipulates this object, or try to use different javascript enumerations to see what I can get from this object.
Maybe a for in loop, just to see where it gets me. After all, many javascript dev tools were built using javascript - they shouldn't have more insight on objects than regular js commands.
I tried to create custom widget for my site. when I loaded page it says:
mixin #0 is not a callable constructor.
clsInfo.cls.prototype is undefined
I can't find any information about clsInfo, so I don't know what is it. maybe the problem that I use dojo from google:
and my own script is located on localhost. so when my dojo on page initializes something goes wrong with my script. I can't find any good info on dojo, maybe I search in wrong places?
please help me to resolve my problem
I ran into this when I was trying to override a dijit.Dialog so I could bind events to controls within it. We've yet to see if the binding part will work, but if you look at the source, this happens when one of the bases passed in as the second argument fails to resolve to an "[Object function]". In my case, I was passing a String in.
dojo.declare takes 3 arguments:
The name of the custom object "class" you're building
An array of base classes, parents to provide functionality (not the string names of those classes)
A hash of functions and declarations
So if I want to override dijit.Dialog, I have to do:
dojo.declare("myDialogType", [dijit.Dialog], {
function1() {/*Code*/},
function2() {/*Code*/}
}
I had ["dijit.Dialog"] as my second argument and that was the problem.
I strongly recommend using Web Inspector or Firebug with uncompressed local copies of the Dojo library rather than the CDN to figure out what's going on and debug these types of problems. Dojo's documentation is extensive but not complete in some areas and some behaviors have to be figured out by looking at what the code expects. That's not intended as a slight to the authors; once you get it going it's a pretty awesome product, and any documentation for volunteer work is appreciated.
Are you sure Dojo is loading? Did you put your code in a dojo.addOnLoad()? When using a CDN you sometimes run into issues with execution times. dojo.addOnLoad() will not only trigger when the DOM is loaded, it gets called when dojo resources have downloaded, such as dijit._Widget.
I've run into this problem when I screw up the order of my requires which makes _WidgetBase not what _WidgetBase really is. Seems like a simple spot to screw up.