Javascript file locked when breakpoint added - javascript

I'm using Visual Studio 2003. In debug mode, whenever I add a break point in my javascript (js) file, the file then becomes locked so that it can't be edited.
Closing the tab and reopening it seems to unlock it.
What I'd like to know is: why does this happen and is there some kind of setting that would prevent this from happening?

I think this is by design. When you hit a breakpoint Visual Studio shows a copy of the actual file. You cannot edit it during debugging.

Found this macro which automatically closes and reopens the js page you are on, and moves the cursor back to the line you are on. Hope it comes in useful to someone.
Imports EnvDTE
Imports System.Diagnostics
Public Module AllowJSModify
Sub ReOpenWindow()
Try
'get line no
Dim objCursorTxtPoint As EnvDTE.TextPoint = GetCursorTxtPnt()
Dim intLine As Integer = objCursorTxtPoint.Line
'get current filename
Dim strActiveWindow = DTE.ActiveWindow.Document.FullName
'close open file (auto-save)
DTE.ActiveWindow.Close(vsSaveChanges.vsSaveChangesYes)
're-open file
Dim item As EnvDTE.ProjectItem = DTE.Solution.FindProjectItem(strActiveWindow)
item.Open()
item.Document.Activate()
'go to prev line no
DTE.ActiveDocument.Selection.GotoLine(intLine)
Catch ex As System.Exception
MsgBox("You are not focused on a line of code.", MsgBoxStyle.Critical, "Error")
End Try
End Sub
Private Function GetCursorTxtPnt() As EnvDTE.TextPoint
Dim objTextDocument As EnvDTE.TextDocument
Dim objCursorTxtPoint As EnvDTE.TextPoint
Try
objTextDocument = CType(DTE.ActiveDocument.Object, EnvDTE.TextDocument)
objCursorTxtPoint = objTextDocument.Selection.ActivePoint()
Catch ex As System.Exception
End Try
Return objCursorTxtPoint
End Function
End Module

Related

Close Excel Workbook from VBA/JScript without crashing Excel

in VBA, I have a global script control variable in JScript language (Javascript ES3). I have the var "ThisWorkbook" set as
var ThisWorkbook = GetObject('', 'Excel.Application').Workbooks('" + ThisWorkbook.Name + "')
Then I can close the workbook by saying
ThisWorkbook.Close(false)
Full VBA code for completion:
Sub Test
Dim ScriptC as Object
Set ScriptC = CreateObject("ScriptControl"): ScriptC.Language = "JScript"
ScriptC.Eval "var ThisWorkbook = GetObject('', 'Excel.Application').Workbooks('" + ThisWorkbook.Name + "')"
ScriptC.Eval "ThisWorkbook.Close(false)"
End Sub
However, this crashes my Excel and all open workbooks (Excel 2016) - what would be a good way to avoid this? I have to do this from JScript/Javascript, but could for example do it through a WScript variable (as long as it's called from within JScript). The reason for this is that it's triggered by an event that's evaluated in JScript and not in VBA (VBA is just the wrapper in this case).
I've tried "ThisWorkbook.Application.Quit' (as per https://learn.microsoft.com/en-us/office/vba/api/excel.application.quit ), but that doesn't work either.
Thanks!
This bug only occurs when running the command from the immediate window - if run from within a subroutine it does NOT crash.
I had tested in immediate a bunch of times before realizing this.
Non-issue, apologies.

Automate 'Right click' and 'Save Target as' in VB

I am working on a program for downloading bills that will automatically navigate to a webpage using the web browser object, log into it, navigate to the Bills page and download the most recent bill.
It all works well up until where I actually download it, as using the invokemember("click") code fires up IE and asks me to log in again which is not what I want to do. The DownloadFile method also does not work, and downloads a file that says the object has been moved to he login URL.
Right clicking and selecting "save target as" from the web browser works, but I'm not sure how to go about automating it.
Edit: Here's the code for the downloading part, parts of it were borrowed from another question on here but I can't remember who or where.
Dim IsRightElement As Boolean = False
For Each curElement As HtmlElement In Browser.Document.Links()
If curElement.GetAttribute("InnerText") = "Download Call Charges" Then
IsRightElement = True
End If
If IsRightElement Then
Dim Link As String = curElement.DomElement.href.ToString()
'This is where I'm stuck
'My.Computer.Network.DownloadFile(Link, "C:\Users\user\Desktop\PhoneBill.csv", "<username>", "<password>")
'The above does not work
'curElement.InvokeMember("contextmenu")
'Not sure what to do here
IsRightElement = False
Exit For
End If
Next
Me.Close()

Not a MessageBox related error that is thrown when using a MessageBox server side

The title is most likely confusing for most, so I'll explain it thoroughly.
This is the error I'm getting:
Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
However, it's not being thrown as a result of a MsgBox being used server side.
Another wrench in the mix, this is only occuring on our current production server. The test server, which is set up identically to the production (with the exception of the SSL Cert being different, but that won't matter), is working flawlessly. The dev machine also works without error.
Current code being used in VB codebehind:
Dim DBconn As New OracleConnect 'Custom class file
Try
DBconn.Open(Uname, Pword, SelServ)
If DBconn Is Nothing Then
errorLabel.Text = "Authentication did not succeed. Check user name and password."
Exit Sub
Else
groups = DBconn.GetUserRole()
'Create the ticket, and add the groups.
Dim isCookiePersistent As Boolean = chkPersist.Checked
Dim authTicket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, _
txtUsername.Text, DateTime.Now, DateTime.Now.AddMinutes(60), isCookiePersistent, groups)
'Encrypt the ticket.
Dim encryptedTicket As String = FormsAuthentication.Encrypt(authTicket)
'Create a cookie, and then add the encrypted ticket to the cookie as data.
Dim authCookie As HttpCookie = New HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
If (isCookiePersistent = True) Then
authCookie.Expires = authTicket.Expiration
End If
'Add the cookie to the outgoing cookies collection.
Response.Cookies.Add(authCookie)
'set session variables
Session("UID") = txtUsername.Text
Session("PWD") = txtPassword.Text
Session("selServ") = StrServer.SelectedValue
SetupTableNames()
'MsgBox(groups, MsgBoxStyle.OkOnly, "HRIS User Role")
Session("gsRole") = groups
'You can redirect now.
'Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUsername.Text, False))
Response.Redirect("~/Account/_Search.aspx")
End If
Catch ex As Exception
errorLabel.Text = "Error authenticating. " & ex.Message
End Try
Code from OracleConnect class:
Public Sub Open(ByVal Uname As String, ByVal Pword As String, ByVal SelServ As String)
OraDb = "Data Source=" + SelServ +
";Persist Security Info=True" +
";User Id=" + Uname +
";Password=" + Pword
conn = New OracleConnection(OraDb)
Try
conn.Open()
Catch ex As OracleException
Select Case ex.Number
Case 1
MesgBox("Error attempting to insert duplicate data.", MsgBoxStyle.OkOnly, "HRIS")
Case 12545
MesgBox("The database is unavailable.", MsgBoxStyle.Critical, "HRIS")
Case Else
MesgBox("Database error: " + ex.Message.ToString(), MsgBoxStyle.Critical, "HRIS")
End Select
Catch ex As Exception
MesgBox(ex.Message.ToString(), MsgBoxStyle.Information, "HRIS")
End Try
End Sub
I'm aware of the MesgBox's in the class file but those are referencing a Sub the uses Javascript that works within the program which has been tested and works as it should.
So my questions are:
Is there something that would trigger this response server side in IIS 7.0 that I haven't found yet?
If it's not viable in IIS, then are there any alternatives that I should look into?
EDIT: The solution to this problem didn't lie within the ASP or VB code but rather with the Oracle set up on the server. For anyone that has a similar problem in the future, I advise looking into the TNS_ADMIN environment/system variables and the TNSNAMES.ORA file and make sure they are correct. If you make any of these changes, make sure to restart the server. My steps involved verifying the TNSNAMES.ORA file was correct, the TNS_ADMIN environment variable was set, then in a cmd prompt using "set tns_admin={filepath}", after all that then restart the server and the site was working perfectly.
The solution to this problem didn't lie within the ASP or VB code but rather with the Oracle set up on the server. For anyone that has a similar problem in the future, I advise looking into the TNS_ADMIN environment/system variables and the TNSNAMES.ORA file and make sure they are correct. If you make any of these changes, make sure to restart the server. My steps involved verifying the TNSNAMES.ORA file was correct, the TNS_ADMIN environment variable was set, then in a cmd prompt using "set tns_admin={filepath}", after all that then restart the server and the site was working perfectly.

Cannot find source of javascript function call

Ok, so I need to find the source code of a particular javascript function on a website. (The specifics do not really matter unless there is no way to do what it is that I am asking)
I can see the function call in a link of html code
onclick="inbox.sendMessage();"
I know that the function does work because if I use a plugin a can call the function on that page, however, I have searched every .js file is referenced in that page, and none of them contain a function called sendMessage.
What I am asking is, is there a way to follow the code back to the source, perhaps if there was a way to debug the html and break when the onclick is triggered and then step into the function to see its source, but I do not know how I can do that or if it is even possible. Any help will be greatly appreciated, Thanks.
I guess you could do :
inbox.sendMessage
In the webconsole. (the function name without the parenthesis)
It will print out the source code of the function.
I usually use Opera, and in that at least this is what I do:
Open Opera Dragonfly (Ctrl + Shift + I).
Click on the HTML tag with the onclick handler.
Go to the listeners tab in the right hand side column.
See the listener for the click event. It shows you the file and line number.
sendMessage could be declared as:
var inbox{
sendMesssage:function(){
}
}
//or
function inbox(){
this.sendMessage=function(){
}
}
// or
inbox.sendMessage=function(){}
// or ...
So looking for "sendMessage(" or "function sendMessage" will not find you anything.
In chrome, Internet Explorer and Firefox (with firebug) you can hit F12 and go to debug, there you can check the scripts that have been loaded as there might have been scripts loaded dynamically.
#!/usr/bin/env ruby
Dir::glob("*").each do |name|
lineCount = 1
File.open(name, "r").each do |line|
puts "\nFile name: " + name + "\nline: " + lineCount.to_s if line =~ /inbox.sendMessage/ && name != "findfunction.rb"
lineCount += 1
end
end
Wrote a quick ruby script to help you out. To execute, first make sure you have a ruby interpreter on your machine then place the script in the directory with all your relevant files. load up a command line terminal, navigate to said directory and type "ruby findfunction.rb".
It will tell you all instances (files + line number) of "inbox.sendMessage".

how to execute javascript in delphi?

I am coding a small app ,in middle i struck at some point where i have to execute javascript to get my data ?
in my process ,i have to login to some url and then go to some page and have to get data from that . i done all this with indy idhttp ,i got all info except one column which needs javascript to get value ,then i tried using twebbowser to make it work for me ,but how can i use cookies to enabled to webbrowser ?
i navigated browserto('http://mysite.com/login.php user and pass ') ,well its loged in and then i tried to access next link like ('http://mysite.com/link1/example.php')but it directing to login page :(
any help appreciated :)
What is your question now? In the title you ask how to execute JavaScript. Try the following:
uses
MSHTML_TLB, SHDocVw, ShellAPI;
function ExecuteScript(doc: IHTMLDocument2; script: string; language: string): Boolean;
var
win: IHTMLWindow2;
Olelanguage: Olevariant;
begin
if doc <> nil then
begin
try
win := doc.parentWindow;
if win <> nil then
begin
try
Olelanguage := language;
win.ExecScript(script, Olelanguage);
finally
win := nil;
end;
end;
finally
doc := nil;
end;
end;
end;
Sample usage:
IDoc: IHTMLDocument2;
Webbrowser1.Document.QueryInterface(IHTMLDocument2, iDoc);
ExecuteScript(iDoc, 'document.login.submit()', 'JavaScript');
(This, and more, can be found here).
Then in the text you ask how to use cookies (when using TWebBrowser this should happen automatically). When using Indy HTTP, you just have to attach a TIdCookieManager to your TIdHTTPClient instance, thats all (but you probably don't want to use that anyway, due to the script requirement....)
Your best bet would be to automate IE itself. Grab a copy of embeddedwb, drop on a form and navigate to the url which you need to execute something. There is a document property of the component which returns an OLEVariant, use this to execute a DHTML style statement.. something like document.form.submit;.
You can easily hide the window used for automation, one technique I have used is to place it on a new page on a page control, add a second page to display the status, then show the status page and hide the tabs.

Categories

Resources