Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: parent is not defined #68

Open
1 task
and-nord opened this issue May 24, 2020 · 2 comments
Open
1 task

ReferenceError: parent is not defined #68

and-nord opened this issue May 24, 2020 · 2 comments
Assignees
Labels
Milestone

Comments

@and-nord
Copy link

Bug Report

Prerequisites

  • Can you reproduce the problem in a MWE?
  • Are you running the latest version of AngleSharp?
  • Did you check the FAQs to see if that helps you?
  • Are you reporting to the correct repository? (there are multiple AngleSharp libraries, e.g., AngleSharp.Css for CSS support)
  • Did you perform a search in the issues?

For more information, see the CONTRIBUTING guide.

Description

I am parsing Kyocera FS-3040MFP+
Index page have frame set

frameset border=0 cols=* frameborder=NO framespacing=0 rows=1,*
frame name=topframe noResize scrolling=no src="../top.htm"
frame name=main src="../start/start.htm"

and javascript that have same vars

<script language="JavaScript"> var opt_msg1_exist = "_mode_on"; if( opt_msg1_exist == "_mode_on") { var opt_msg1_name = '>Português'; } var OEMFlag = 0; if( OEMFlag == 0 || OEMFlag == 2) { document.write('<title>Kyocera Command Center</title>'); document.write(''); } else document.write('<title></title>'); var lang="rus"; var ModelName="FS-3040MFP+"; var IEMsgShown = false; var currentpage=""; var testData = new Array(); testData[0] = 0; var curPageFlag = false; </script>

When run start.htm that have into javascript where set var:
Line 45: parent.FaxNum = FaxNum;
Line 48: parent.CipherCheck = 1;
Line 50: parent.CipherCheck = 0;
etc

As result
Script parsing stops with an error "ReferenceError: parent is not defined"

Steps to Reproduce

  1. [First Step]
    var srvJsScripting = new JsScriptingService();
    var srvNavigator = new Navigator();
    var config = Configuration.Default.WithDefaultLoader(new LoaderOptions { IsResourceLoadingEnabled = true }).With(srvNavigator)
    .WithLocaleBasedEncoding().WithCulture("ru-ru").With(srvJsScripting);
    var context = BrowsingContext.New(config);
    var queryDocument = context.OpenAsync("http://mfu01.al.loc").Result;

  2. [Second Step]
    When page start.htm is was processed throw exception "ReferenceError: parent is not defined" and treatment of script is stopped and run next script where into have "parent.Var = " and this have the same error

  3. [and so on...]

Expected behavior:
I want to get variables from the environment of the parent window, read and write data from the child window
Actual behavior:
throw exception "ReferenceError: parent is not defined"
Environment details:
VS 2019, last version of AngleSharp.JS

Possible Solution

Add a property "parent" to the object "Window" to have access to the variables of the parent page
https://developer.mozilla.org/en-US/docs/Web/API/Window/parent

@and-nord and-nord added the bug label May 24, 2020
@and-nord
Copy link
Author

I found a connection between the current window and the parent. And I was able to get the instance with the variables of the parent window.
var oParent = Window->Document->Context->Parent->Current;
next get instance from document
...\AngleSharp.Js\v.0.14.0\src\AngleSharp.Js\JsScriptingService.cs (line 104)
internal EngineInstance GetOrCreateInstance(IDocument document)
{
var objectContext = document.DefaultView;

        if (!_contexts.TryGetValue(objectContext, out var instance))
        {
            var libs = GetAssemblies(document.Context).ToArray();
            instance = new EngineInstance(objectContext, _external, libs);
            _contexts.Add(objectContext, instance);
        }

        return instance;
    }

It's on my knee, but I would like to get a competent code

@FlorianRappl FlorianRappl self-assigned this May 27, 2020
@FlorianRappl
Copy link
Contributor

I'll try to look into it! Just quite under water right now...

@FlorianRappl FlorianRappl added this to the v1.0 milestone Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants