# In app browser

**URL:** <https://forum.ionicframework.com/t/in-app-browser/130116>\
**Category:** ionic-v3\
**Created:** [May 9, 2018, 2:09pm UTC](https://forum.ionicframework.com/t/in-app-browser/130116 "2018-05-09T14:09:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alberthoekstra](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@Alberthoekstra](https://forum.ionicframework.com/u/Alberthoekstra)\
**Post date:** [May 9, 2018, 2:09pm UTC](https://forum.ionicframework.com/t/in-app-browser/130116/1 "2018-05-09T14:09:35Z")

</div>

Hi,

So I have a project to build an app, that downloads a zip file that contains a HTML file, CSS and JS files.  
I’ve managed to download the zip, save it to the disk and extract the content.

Now I’m trying to open the HTML file and render it in the app. I think i should use the In-app-browser plugin. But i cant get it to work yet.

In a empty page I’ve put this code into the ionViewDidLoad() method:

```auto
    const browser = this.iab.create('file://DIRECTORY/Index.html', '_self');
    browser.show();

```

iab is a private variable of type InAppBrowser in the constructor of that page.  
The file path is different but this is for the example.

The method will run, I’ve checked that with logging. But the app won’t load the file and doesn’t show it.  
Also no errors or what so ever.

Anyone know’s what im missing?

Kind regards.

---

<div class="post-metadata">

**Author:** ![saimon](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/saimon/32/133587_2.png) [@saimon](https://forum.ionicframework.com/u/saimon)\
**Post date:** [May 9, 2018, 2:47pm UTC](https://forum.ionicframework.com/t/in-app-browser/130116/2 "2018-05-09T14:47:04Z")

</div>

2 things here…

1. You said you added the code to your view did load. Please always make sure that Cordova is initialised and your plugins are available when executing a function that early! You can simply wrap it in the platform ready event like:

```auto
this.plt.ready().then((readySource) => {
      // Do your stuff with iab now
});

```

1. The URL to the file could be wrong. Try to add a file to your assets and serve that dummy file to see if your call is actually working like it should.

Finally, I’m not sure if the in app browser will load/serve the full content of your package or just that one file. Another solution might be to start a lightweight server that serves those assets, for that check out the [httpd plugin](https://ionicframework.com/docs/native/httpd/)!

---

<div class="post-metadata">

**Author:** ![Alberthoekstra](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@Alberthoekstra](https://forum.ionicframework.com/u/Alberthoekstra)\
**Post date:** [May 11, 2018, 10:18am UTC](https://forum.ionicframework.com/t/in-app-browser/130116/3 "2018-05-11T10:18:17Z")

</div>

Hi Saimon,

Thanks for you suggestions.  
I would like to use the Httpd plugin.  
I’ve installed it and trying to get it running.

Could you help me out again maybe?  
The current issue i have is:

```auto
INTERNAL ERROR: serveFile(): given homeDir is not a directory

```

I start the server like this:

```auto
const dataDir = await this.file.resolveDirectoryUrl(this.file.externalDataDirectory);
const websiteDir = await this.file.getDirectory(dataDir, 'website', null);
const indexFile = await this.file.getFile(websiteDir, 'index.html', null);

let options: HttpdOptions = {
www_root: indexFile.nativeURL, // file:///storage/emulated/0/Android/data/io.test.testapp/files/website/index.html
port: 9000,
localhost_only: true
};

this.httpd.startServer(options).subscribe(url => {
console.log('Server is live');
const iabPage = iab.create(url, '_self', 'location=yes');
});

```

I know I’m giving the url of the file, I’ve also tried to give the url of the directory like this:

```auto
let options: HttpdOptions = {
www_root: websiteDir.nativeURL, // file:///storage/emulated/0/Android/data/io.test.testapp/files/website/
port: 9000,
localhost_only: true
};

```

What am I doing wrong.  
I think the directory url should be different, but I cannot figure out what it should be.

---

<div class="post-metadata">

**Author:** ![Alberthoekstra](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@Alberthoekstra](https://forum.ionicframework.com/u/Alberthoekstra)\
**Post date:** [May 11, 2018, 1:45pm UTC](https://forum.ionicframework.com/t/in-app-browser/130116/4 "2018-05-11T13:45:13Z")

</div>

This afternoon I’ve learned that the path is relatieve to the WWW folder.  
That means that only the folder names that are inside the WWW folder could be used to create a webserver with.

Unfortunately you can’t put a path on the external sd card or something.  
I can’t unzip the files from the file to the application data folder.

Anyone has another solution?

---

<div class="post-metadata">

**Author:** ![Alberthoekstra](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@Alberthoekstra](https://forum.ionicframework.com/u/Alberthoekstra)\
**Post date:** [May 15, 2018, 2:36pm UTC](https://forum.ionicframework.com/t/in-app-browser/130116/5 "2018-05-15T14:36:35Z")

</div>

Okay, so the problem is the URL to the location.

The location I’ve mentioned in my last message was like this.

```auto
websiteDir.nativeURL // file:///storage/emulated/0/Android/data/io.test.testapp/files/website/

```

The problem is the file:// prefix. Whenever you substring this and use it as www\_root value it works.

To make a complete working example:

```auto
const dataDir = await this.file.resolveDirectoryUrl(this.file.externalDataDirectory);
const websiteDir = await this.file.getDirectory(dataDir, 'website', null);

let options: HttpdOptions = {
www_root: websiteDir.nativeURL.substring(7), // /storage/emulated/0/Android/data/io.test.testapp/files/website/
port: 9000,
localhost_only: true
};

this.httpd.startServer(options).subscribe(url => {
console.log('Server is live');
const iabPage = iab.create(url, '_self', 'location=yes');
});

```

---

<div class="post-metadata">

**Author:** ![pulkit1611](https://avatars.discourse-cdn.com/v4/letter/p/a87d85/32.png) [@pulkit1611](https://forum.ionicframework.com/u/pulkit1611)\
**Post date:** [December 26, 2018, 4:57pm UTC](https://forum.ionicframework.com/t/in-app-browser/130116/6 "2018-12-26T16:57:42Z")

</div>

Thank you so much for this… Was stuck here for almost 2 weeks…Thank you once again…

---

<div class="post-metadata">

**Author:** ![Alberthoekstra](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@Alberthoekstra](https://forum.ionicframework.com/u/Alberthoekstra)\
**Post date:** [December 26, 2018, 5:44pm UTC](https://forum.ionicframework.com/t/in-app-browser/130116/7 "2018-12-26T17:44:26Z")

</div>

No problem! Goodluck

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:36pm UTC](https://forum.ionicframework.com/t/in-app-browser/130116/8 "2021-07-19T21:36:51Z")

</div>

Closed on July 19, 2021, 9:36pm UTC


