Skip to content

WVJB doesn't work with JavaScript loaded with windowScriptObject? #52

@zakdances

Description

@zakdances

This isn't a huge deal, but I just wanted to confirm whether anyone has experienced this issue. I'm trying to load dynamically-created HTML in my webView:

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"about:blank"]];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

[self.mainFrame loadRequest:request];
[self setEditable:YES];
[self setNeedsDisplay:YES];

NSBundle *webTechBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle]   
                                    pathForResource:@"MyWebTechBundle"
                                    ofType:@"bundle"]];

NSMutableArray *scripts = @[@"js1.js", @"js2.js", @"js3.js"].mutableCopy;
for (NSString *script in scripts.copy) {
    NSString *filePath  = [webTechBundle pathForResource:[script stringByDeletingPathExtension] ofType:script.pathExtension];
    NSString *fileContents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
    [scripts replaceObjectAtIndex:[scripts indexOfObject:script] withObject:fileContents];
}

[self.windowScriptObject evaluateWebScript:[scripts componentsJoinedByString:@";"]];

self.webViewbridge = [WebViewJavascriptBridge bridgeForWebView:self handler:^(id data, WVJBResponseCallback responseCallback) {

            NSLog(@"from DOM: %@", data);

}];

Whatever I do to dynamically load scripts, WBJB never works. It only seems to work with pre-defined html files. Has any testing been done with windowScriptObject?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions